Saa*_*med 4 networking dns dnsmasq 23.10
以下是我从命令行调试此问题的方法:
$ dnsmasq --no-daemon --log-queries
Run Code Online (Sandbox Code Playgroud)
将log-queries
选项放入配置文件中并将其作为守护进程运行,日志文件中仍然没有显示任何内容。我期待当我这样做时dig example.com
,它应该出现。
这是上面命令的输出:
dnsmasq: started, version 2.89 cachesize 150
dnsmasq: compile time options: IPv6 GNU-getopt DBus no-UBus i18n IDN2 DHCP DHCPv6 no-Lua TFTP conntrack ipset nftset auth cryptohash DNSSEC loop-detect inotify dumpfile
dnsmasq: reading /etc/resolv.conf
dnsmasq: using nameserver 8.8.8.8#53
dnsmasq: using nameserver 1.1.1.1#53
dnsmasq: using nameserver 2001:4860:4860::8888#53
dnsmasq: using nameserver 2001:4860:4860::8844#53
dnsmasq: read /etc/hosts - 7 names
Run Code Online (Sandbox Code Playgroud)
Ubuntu版本:23.10
内核6.5.0
dnsmasq版本:2.89
就dig @127.0.0.1 example.com
这样做吧。对于整个系统,请跳至下面的正确解决方案。
您的行dnsmasq: using nameserver 8.8.8.8
显示您/etc/resolv.conf
已远离 systemd-resolved 进行了编辑。现在的问题不在于 dnsmasq 没有记录查询。问题是查询没有发送到 dnsmasq。每个应用程序都会调用getaddrinfo
glibc 函数,该函数会查看/etc/resolv.conf
. 在本例中,正在读取该文件,并直接dig
向 发出 DNS 请求,而不询问.8.8.8.8
dnsmasq
systemd-resolved 编辑该/etc/resolv.conf
文件是有原因的。它这样做是为了使用127.0.0.53
. 这样做dnsmasq
只会导致无限循环,因为dnsmasq
使用该文件本身。systemd-resolved
不会遇到这个问题,因为它使用/etc/systemd/resolved.conf
. 我们可以用适当的解决方案来复制它:
编辑:请参阅 Pihhan 的简单答案https://askubuntu.com/a/1501802/1004020。它可以做到这一点,只是步骤更少。
sudo mv /etc/resolv.conf /etc/resolv-for-dnsmasq.conf
echo 'nameserver 127.0.0.1' | sudo tee /etc/resolv.conf
dnsmasq --no-daemon --log-queries -r /etc/resolv-for-dnsmasq.conf
改为启动服务器dig example.com
所有其他应用程序都应该开始受益于 dnsmasq 的缓存dnsmasq
Ubuntu 23.10默认不使用。它使用systemd-resolved
,因此使用相应的命令:
sudo resolvectl log-level debug
dig example.com
或使用resolvectl query --cache=0 example.com
sudo journalctl -r -u systemd-resolved
sudo resolvectl log-level info
归档时间: |
|
查看次数: |
302 次 |
最近记录: |