新聞中心
搭建一個屬于自己的本地DNS服務(wù)器很有必要,本篇文章將使用Dnsmasq為大家演示一下搭建DNS服務(wù)器具體方法。

img
一、Dnsmasq安裝
安裝并啟動Dnsmasq
yum install -y dnsmasq
service dnsmasq start
二、Dnsmasq配置
1、Dnsmasq的配置文件路徑為:/etc/dnsmasq.conf
# ll -d /etc/dnsmasq.conf
-rw-r--r-- 1 root root 21237 Feb 23 00:17 /etc/dnsmasq.conf
2、編輯/etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf //dnsmasq 會從這個文件中尋找上游dns服務(wù)器
strict-order //去掉前面的#
addn-hosts=/etc/dnsmasq.hosts //在這個目里面添加記錄
listen-address=127.0.0.1,192.168.1.123 //監(jiān)聽地址
3、修改/etc/resolv.conf
echo 'nameserver 127.0.0.1' > /etc/resolv.conf
4、創(chuàng)建resolv.dnsmasq.conf文件并添加上游dns服務(wù)器的地址
touch /etc/resolv.dnsmasq.conf
echo 'nameserver 119.29.29.29' > /etc/resolv.dnsmasq.conf
5、創(chuàng)建dnsmasq.hosts文件
cp /etc/hosts /etc/dnsmasq.hosts
echo 'addn-hosts=/etc/dnsmasq.hosts' >> /etc/dnsmasq.conf
提示:resolv.dnsmasq.conf中設(shè)置的是真正的Nameserver,可以用電信、聯(lián)通等公共的DNS。
三、Dnsmasq啟動
1、設(shè)置Dnsmasq開機(jī)啟動并啟動Dnsmasq服務(wù):
chkconfig dnsmasq on
/etc/init.d/dnsmasq restart
2、netstat -tunlp|grep 53 查看Dnsmasq是否正常啟動:
# netstat -tlunp|grep 53
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 2491/dnsmasq
tcp 0 0 :::53 :::* LISTEN 2491/dnsmasq
udp 0 0 0.0.0.0:53 0.0.0.0:* 2491/dnsmasq
udp 0 0 :::53 :::* 2491/dnsmasq
3、dig www.freehao123.com,第一次是沒有緩存,所以時間是200多
使用Dnsmasq搭建本地dns服務(wù)器上網(wǎng)使用Dnsmasq搭建本地dns服務(wù)器上網(wǎng)
4、第二次再次測試,因?yàn)橐呀?jīng)有了緩存,所以查詢時間已經(jīng)變成了0.
使用Dnsmasq搭建本地dns服務(wù)器上網(wǎng)使用Dnsmasq搭建本地dns服務(wù)器上網(wǎng)
分享標(biāo)題:使用Dnsmasq搭建DNS服務(wù)器具體方法
本文鏈接:http://m.fisionsoft.com.cn/article/dhpgpss.html


咨詢
建站咨詢
