我想在 ubuntu 15.10 上设置 的上游服务器dnsmasq
。我读了很多关于 dnsmasq 的文档或资源,其中提到了一个名为 的配置文件/etc/dnsmasq.conf
,但我找不到它。我试图找出系统启动时是如何启动的,但在 下也dnsmasq
找不到。dnsmasq
/etc/init.d
那么我应该修改哪个文件来设置上游服务器dnsmasq
?
答案1
您可以按照下列步骤操作:
如果您的系统运行 dhcp 客户端,则编辑 dhclient.conf,您必须取消注释/修改该prepend domain-name-server
部分,如下所示:
prepend domain-name-servers 8.8.8.8;
创建一个包含以下内容的文件/etc/resolv.dnsmasq.conf
:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver <your ISP DNS>
/usr/share/doc/dnsmasq-base/examples/dnsmasq.conf.example
复制文件/etc/NetworkManager/dnsmasq.d/dnsmasq.conf
并根据需要进行修改。您必须添加以下行:
resolv 文件=/etc/resolv.dnsmasq.conf
然后使用 networkmanager 启动 dnsmasq。编辑文件,/etc/NetworkManager/NetworkManager.conf
在 [main] 部分插入 dns=dnsmasq
尝试挖掘:
dig www.google.com
; <<>> DiG 9.9.5-9+deb8u2-Debian <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 45033
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 299 IN A 74.125.232.147
www.google.com. 299 IN A 74.125.232.144
www.google.com. 299 IN A 74.125.232.145
www.google.com. 299 IN A 74.125.232.146
www.google.com. 299 IN A 74.125.232.148
;; Query time: 29 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Dec 17 01:43:19 CET 2015
;; MSG SIZE rcvd: 123
然后重新启动网络和 NetworkManager 并重试挖掘:
systemctl restart networking
systemctl restart NetworkManager
dig www.google.com
; <<>> DiG 9.9.5-9+deb8u2-Debian <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34735
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 299 IN A 74.125.232.144
www.google.com. 299 IN A 74.125.232.147
www.google.com. 299 IN A 74.125.232.145
www.google.com. 299 IN A 74.125.232.148
www.google.com. 299 IN A 74.125.232.146
;; Query time: 30 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Dec 17 01:46:38 CET 2015
;; MSG SIZE rcvd: 123
正如你所看到的解析器现在是 127.0.0.1。如果你再挖掘一下,你会看到查询时间将减慢到 0。这表明 dnsmasq 正在运行。