輕量級的DNS服務器--DNSmasq
發布時間:2020-06-18 點擊數:1593
簡介:
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多年,為廣大用戶提供專業化深圳服務器托管,深圳服務器租用,深圳主機托管 ,云服務器租用等服務器資源,詳情歡迎咨詢客服了解。
上一篇:運行常用命令