轻量级的DNS服务器--DNSmasq
发布时间:2020-06-18 点击数:1524
简介:
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
dnsmasq是轻量级DNS服务器和一个开源项目。配置简单,快速。 Dnsmasq提供DNS缓存和DHCP服务功能。作为域名解析服务器(DNS),dnsmasq可以缓存DNS请求以提高与已访问网站的连接速度。作为DHCP服务器,dnsmasq可以为LAN计算机提供Intranet 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
全网数据专注IDC多年,为广大用户提供专业化深圳服务器托管,深圳服务器租用,深圳主机托管 ,云服务器租用等服务器资源,详情欢迎咨询客服了解。
上一篇:运行常用命令