重新启动 dnsmasq 时,resolv.conf 不断被覆盖,从而破坏 dnsmasq

nul*_*ser 10 networking linux dns debian dnsmasq

我正在运行 Debian Jessie,我正在尝试将 dnsmasq 配置为缓存 DNS 服务器。我使用指南提出了以下建议/etc/dnsmasq.conf

listen-address=127.0.0.1
bind-interfaces
domain-needed
bogus-priv
no-hosts
dns-forward-max=150
cache-size=1000
neg-ttl=3600
resolv-file=/etc/resolv.dnsmasq
no-poll
Run Code Online (Sandbox Code Playgroud)

sudo service dnsmasq restart失败,它不会开始,告诉我

Mar 26 17:13:01 user dnsmasq[26743]: dnsmasq: syntax check OK.
Mar 26 17:13:01 user dnsmasq[26746]: dnsmasq: only one resolv.conf file allowed in no-poll mode.
Run Code Online (Sandbox Code Playgroud)

好吧,有点奇怪,直接从指南中提取的配置失败了。我将删除该no-poll选项以查看它是否有效。这次它开始得很好,但 DNS 解析显然失败了。相关文件:

/etc/resolv.conf

nameserver 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

/etc/resolv.dnsmasq

nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)

/var/run/dnsmasq/resolv.conf

nameserver 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

第三个文件似乎是 dnsmasq 的实时 resolv.conf 文件,因为在 dnsmasq 已经运行时向其中添加名称服务器行会导致 DNS 解析立即开始工作。所以看起来它忽略了我的/etc/resolv.dnsmasq. 我还尝试在 my 中添加一个名称服务器行/etc/resolv.conf并删除 中的resolv-file/etc/dnsmasq.conf,但它会立即被覆盖为您在执行时在上面看到的内容sudo service dnsmasq restart

dnsmasq 发生了什么,我是否将 dnsmasq 配置为缓存 DNS 服务器?

big*_*osh 13

似乎是在启动脚本中的错误对于dnsmasq使用resolvconf到揍本地域名解析,如果本地loopback接口并没有明确except的在-ed/etc/defaults/dnsmasq文件。

简短的回答是,您可以添加...

DNSMASQ_EXCEPT=lo
Run Code Online (Sandbox Code Playgroud)

/etc/defaults/dnsmasq解决这个问题。

有关更多信息,请参阅此问题...

https://raspberrypi.stackexchange.com/questions/37439/proper-way-to-prevent-dnsmasq-from-overwriting-dns-server-list-supplied-by-dhcp


小智 5

bigjosh 是对的——除了 dnsmasq 有更新,现在有一个选项/etc/default/dnsmasq,你可以在末尾取消散列:

IGNORE_RESOLVCONF=yes
Run Code Online (Sandbox Code Playgroud)