1. 程式人生 > >輕量級的DNS服務器--DNSmasq

輕量級的DNS服務器--DNSmasq

輕量級的dns服務器--dnsmasq

簡介:

dnsmasq時一款輕量級的DNS服務器,同時也是開源項目,配置簡單快捷,Dnsmasq提供DNS緩存和DHCP服務功能。作為域名解析服務器(DNS),dnsmasq可以通過緩存DNS請求來提高對訪問過的網址的連接速度。作為DHCP服務器,dnsmasq可以為局域網電腦提供內網ip地址和路由,DNS和DHCP兩個功能可以同時或分別單獨實現。dnsmasq輕量且易配置,此外它還自帶了一個PXE服務器以及對郵件服務器的mx記錄的支持,jabber的srv記錄的支持等。


部署環境:

Centos 6.5 x86_64操作系統

dnsmasq時base源中的軟件包,可以直接安裝部署:

# yum list | grep dnsmasq
dnsmasq.x86_64                              2.48-17.el6                  @base 
dnsmasq-utils.x86_64                        2.48-17.el6                  base

安裝dnsmasq軟件包:

#yum -y install dnsmasq

操作之前先做備份:

# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak

#查看dnsmasq的安裝文件路徑:

# rpm -ql dnsmasq
/etc/dbus-1/system.d/dnsmasq.conf
/etc/dnsmasq.conf            #主配置文件
/etc/dnsmasq.d
/etc/rc.d/init.d/dnsmasq
/usr/sbin/dnsmasq
/usr/share/doc/dnsmasq-2.48
/usr/share/doc/dnsmasq-2.48/CHANGELOG
/usr/share/doc/dnsmasq-2.48/COPYING
/usr/share/doc/dnsmasq-2.48/DBus-interface
/usr/share/doc/dnsmasq-2.48/FAQ
/usr/share/doc/dnsmasq-2.48/doc.html
/usr/share/doc/dnsmasq-2.48/setup.html
/usr/share/man/man8/dnsmasq.8.gz
/var/lib/dnsmasq

將本地的resolv解析文件配置指向本機:

#echo ‘nameserver 127.0.0.1‘ > /etc/resolv.conf

copy一份作為dnsmasq的解析配置文件:

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
echo ‘nameserver 8.8.8.8‘ > /etc/resolv.dnsmasq.conf

dnsmasq使用到的配置文件如下:

# cat /etc/dnsmasq.conf  | grep -v ‘^#‘ | grep -v ‘^$‘
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
interface=eth0
listen-address=192.168.30.131,127.0.0.1
bind-interfaces
addn-hosts=/etc/hosts    #域名映射文件

其他兩個配置文件的內容:

[[email protected] etc]# cat /etc/resolv.conf
nameserver 127.0.0.1

[[email protected] etc]# cat /etc/resolv.dnsmasq.conf
nameserver 8.8.8.8        #4個8谷歌的dns服務器,可能會比較慢
nameserver 114.114.114.114

添加域名映射

# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.30.128    sh-puppet-master.com
192.168.30.130    sh-puppet-node1.com
192.168.30.131    sh-puppet-node2.com

啟動dnsmasq服務:

# /etc/init.d/dnsmasq restart
Shutting down dnsmasq:                                     [  OK  ]
Starting dnsmasq:                                          [  OK  ]

測試查看域名解析的ip:

# dig sh-puppet-node2.com


為了防止本地域名可能會和公網上的一些域名重復,所以改為127.0.0.1.

[[email protected] ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search shjygw com
#nameserver 202.96.209.5
nameserver 127.0.0.1
[[email protected] ~]# cat /etc/resolv.dnsmasq.conf
nameserver 127.0.0.1

測試ping百度發現不ok,但是不影響內網域名解析:

[[email protected] ~]# ping www.baidu.com

ping: unknown host

www.baidu.com


說明:圖片毀壞就不展示了,有空補上.

本文出自 “螞蟻” 博客,請務必保留此出處http://215687833.blog.51cto.com/6724358/1944587

輕量級的DNS服務器--DNSmasq