这是(X)Ubuntu 18.04 Bionic的解决方案。
安装dnsmasq
sudo apt install dnsmasq
在端口53上禁用systemd-resolved侦听器(请勿触摸/etc/systemd/resolved.conf,因为升级时可能会覆盖它):
$ cat /etc/systemd/resolved.conf.d/noresolved.conf
[Resolve]
DNSStubListener=no
然后重新启动
$ sudo systemctl restart systemd-resolved
(或者通过完全禁用它$ sudo systemctl disable systemd-resolved.service
)
删除/etc/resolv.conf并再次创建。这很重要,因为默认情况下resolv.conf是/run/systemd/resolve/stub-resolv.conf的符号链接。如果您不删除符号链接,则重启后systemd将覆盖该文件(即使我们禁用了systemd-resolved!)。NetworkManager(NM)还会检查它是否是检测系统解析的配置的符号链接。
$ sudo rm /etc/resolv.conf
$ sudo touch /etc/resolv.conf
禁用NM对/etc/resolv.conf的覆盖(也有一个rc-manager选项,但是尽管在NM手册中有描述,但它不起作用):
$ cat /etc/NetworkManager/conf.d/disableresolv.conf
[main]
dns=none
并重新启动它:
$ sudo systemctl restart NetworkManager
告诉dnsmasq使用来自NM的resolv.conf:
$ cat /etc/dnsmasq.d/nmresolv.conf
resolv-file=/var/run/NetworkManager/resolv.conf
并重新启动它:
$ sudo systemctl restart dnsmasq
使用dnsmasq解决:
$ cat /etc/resolv.conf
# Use local dnsmasq for resolving
nameserver 127.0.0.1
sudo systemctl disable systemd-resolved
?如果配置正确,则dnsmasq应该可以处理我认为的域解析。