天天看點

IDC伺服器安裝dnsmasq

場景介紹:由于之前使用的阿裡雲的privatezone,如果主機都在阿裡雲還挺友善的,不過最近要搞遷移到IDC機房,是以還是需要本地的一個DNS解析伺服器。

Dnsmasq是一個很實用的小工具,解決區域網路的需求看來非常合适,特别是網關和防火牆上。

它同時也可以作為一個dns查詢伺服器,雖然不如bind等完善,但基本功能也夠用了。

它可以提供如下幾個實用的功能:

1 提供dns服務

2 優先使用本地自定義dns

3 提供dhcp服務

解決一下問題

1 區域網路有很多機器希望使用一份一樣的hosts定義一批名稱對應的ip,你需要經常維護這份清單,可以使用saltstack同步是以minion的hosts。

2 你希望區域網路的人通路某個域名時,攔截下來到指定的ip,做緩存節省帶寬或者其它用途都可以

3 禁止某個域名的正常解析

dnsmasq安裝、配置、域名解析、域名屏蔽等内容

主機定為:192.168.23.4

1.安裝dnsmasq:

yum install dnsmasq -y

2.修改系統配置檔案

echo 'nameserver 127.0.0.1' > /etc/resolv.conf

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf

echo 'nameserver 8.8.8.8' > /etc/resolv.dnsmasq.conf

echo 'nameserver 202.106.0.20' > /etc/resolv.dnsmasq.conf

cp /etc/hosts /etc/dnsmasq.hosts

3.dnsmasq配置

dnsmasq的配置檔案為/etc/dnsmasq.conf,編輯該檔案,添加内容如下:

cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak #先做個備份

echo 'resolv-file=/etc/resolv.dnsmasq.conf' >> /etc/dnsmasq.conf

echo 'addn-hosts=/etc/dnsmasq.hosts' >> /etc/dnsmasq.conf

4.添加開機啟動并啟動服務

chkconfig dnsmasq on

/etc/init.d/dnsmasq restart

驗證伺服器已啟動

netstat -tunlp|grep 53

tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 10246/dnsmasq

udp 0 0 0.0.0.0:53 0.0.0.0:* 10246/dnsmasq

确認服務啟動後,就可以将用戶端PC的DNS伺服器指向dnsmasq伺服器(注意iptables),可以正常通路網絡頁面為正常!

5.測試

把dnsmasq伺服器的dns指向公網的DNS

再把其他内網的主機的dns指向這個我們剛搭建的dnsmasq

繼續閱讀