1. 程式人生 > >dnsmasq搭建簡易dns服務器

dnsmasq搭建簡易dns服務器

dnsmasq

系統:centos6.8_x64

本機IP:172.17.41.243


為了簡便直接使用yum安裝dnsmasq

yum install -y dnsmasq

安裝後編輯配置文件/etc/dnsmasql.cof

cp /etc/dnsmasq.conf /etc/dnsmasq.conf.ori
> /etc/dnsmasq.conf
[[email protected] ~]# cat /etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf
strict-order
#listen-address=172.17.41.243
addn-hosts=/etc/sou_hosts
address=/ganmu.com/172.17.41.243

簡單的進行上述配置即可。

需要註意的是:

1、其中

listen-address=172.17.41.243

如果被註釋掉,或為如下形式

listen-address=172.17.41.243,127.0.0.1

則監聽所有IP的53端口。此時就算/etc/resolv.conf中未配置任何選項,本機也能ping通

address=/ganmu.com/172.17.41.243

中的ganmu.com網址。

如果啟用了下面設置

listen-address=172.17.41.243

即未被註釋掉,此時使用ss -tunl命令查看的監聽端口是監聽所有端口,但是/etc/resolv.conf文件中無論是設置為nameserver 127.0.0.1或者是不設置任何選項,本機都不能ping通/etc/dnsmasq.conf文件中設置都域名。

2、如果想讓其他主機通過此主機進行解析,記得要關閉此dnsmasq主機的防火墻,以及selinux


剩下的如果想訪問外網,或者想把自己想要的域名解析添加進來,就根據/etc/dnsmasq.conf文件中的配置創建文件

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf
[[email protected] ~]# cat /etc/resolv.dnsmasq.conf
nameserver 223.5.5.5
[[email protected] ~]# cat /etc/sou_hosts
172.17.41.243	
/etc/init.d/dnsmasq start

其中/etc/resolv.dnsmasq.conf中配置的地址的作用是:當dnsmasq查找本機的/etc/hosts和/etc/sou_hosts文件內容後,沒有找到域名對應的IP後,就到/etc/resolv.dnsmasq.conf文件中設置的DNS服務器進行解析,解析後返回給dns客戶端。


參考:

https://segmentfault.com/a/1190000006756321

http://www.knowsky.com/888297.html



https://wiki.archlinux.org/index.php/Dnsmasq_(簡體中文)

http://www.knowsky.com/888297.html

http://www.360doc.com/content/14/0913/13/8314158_409140713.shtml

https://my.oschina.net/48474/blog/292366

https://www.oschina.net/news/46697/dnsmasq-2-68

https://www.baidu.com/s?wd=dnsmasq&rsv_spt=1&rsv_iqid=0xc5079a86000002c4&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&rqlang=cn&tn=baiduhome_pg&rsv_enter=1&oq=dnsmasq%25E8%25AF%259E%25E7%2594%259F%25E6%2597%25B6%25E9%2597%25B4&rsv_t=8c906Uu5NAjVhoL4fvme3n%2B1xJct2KIc%2Bqs8BYpGwy%2Bv39dNv1eYFRB9kTiKar2IbXYl&rsv_pq=e25c2b5800009973&inputT=3685&rsv_sug3=42&bs=dnsmasq%E8%AF%9E%E7%94%9F%E6%97%B6%E9%97%B4

https://my.oschina.net/48474/blog/292366


本文出自 “甘木” 博客,請務必保留此出處http://ganmu.blog.51cto.com/9305511/1960921

dnsmasq搭建簡易dns服務器