简介:
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 #域名映射文件
其他两个配置文件的内容:
[root@sh-puppet-node2 etc]# cat /etc/resolv.conf
nameserver 127.0.0.1
[root@sh-puppet-node2 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 ]
就将node2的reslove.conf文件地址指向dns服务器的ip,测试查看域名解析的ip:
# dig sh-puppet-node2.com

为了防止本地域名可能会和公网上的一些域名重复,所以改为127.0.0.1.
[root@sh-puppet-node2 ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search shjygw com
#nameserver 202.96.209.5
nameserver 127.0.0.1
[root@sh-puppet-node2 ~]# cat /etc/resolv.dnsmasq.conf
nameserver 127.0.0.1
测试ping百度发现不ok,但是不影响内网域名解析:
[root@sh-puppet-node2 ~]# ping www.baidu.com
ping: unknown host
www.baidu.com
说明:图片毁坏就不展示了,有空补上.