我认为 systemd-resolved 是无法修复的垃圾,我想替换它。我有自己的本地 DNS 服务器,地址是 192.168.1.2。我会还想要使用 NetExtender 连接到 VPN,它为我提供了 .local 域的 DNS 服务器。我希望这两个功能可以协同工作,我该怎么做?
答案1
Gannet 的回答是错误的。如果您想像在早期版本中一样使用普通的 ifupdown,不使用 netplan 或 NetworkManager(例如在服务器上),而是使用 dhcp,您需要执行以下操作:
systemctl disable systemd-resolved.service
systemctl stop systemd-resolved.service
# check if resolv.conf is pointing to resolvconf
ls -la /etc/resolv.conf
# lrwxrwxrwx 1 root root 27 May 7 16:15 /etc/resolv.conf -> /run/resolvconf/resolv.conf
# if not, delete /etc/resolv.conf and symlink it like this:
rm /etc/resolv.conf
ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
# this will remove the resolved stub resolver entry from resolv.conf
resolvconf -d systemd-resolved
# fix dhclient scripts
chmod -x /etc/dhcp/dhclient-enter-hooks.d/resolved
chmod +x /etc/dhcp/dhclient-enter-hooks.d/resolvconf
# on my machine just chmod -x wasn't enough, I had to move the resolved script somewhere else
mv /etc/dhcp/dhclient-enter-hooks.d/resolved ~
# ifdown/ifup your interface to regenerate resolv.conf (or systemctl restart ifup@eth0)
ifdown eth0; ifup eth0
# check /etc/resolv.conf has the right settings
答案2
您随时可以通过命令禁用 systemd-resolved
systemctl disable systemd-resolved.service
。然后运行:
sudo rm /etc/resolv.conf && sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
以使用/etc/resolv.conf
配置,就像以前的 ubuntu 版本一样。
答案3
这两种答案都可能导致 VPN 问题。此外,如果希望保留 NetworkManager,可以执行以下操作:
如果 resolvconf 与 resolvectl 链接,则取消链接:
ls -lah $(which resolvconf)
如果resolveconf链接到resolvectl,如下所示:
/usr/local/bin/resolvconf -> /usr/bin/resolvectl
我们需要取消链接:
sudo unlink /usr/local/bin/resolvconf
现在,安装 resolvconf,因为大多数 VPN 都使用它:
sudo apt-get install resolvconf
设置dns=none
为[main]
部分/etc/NetworkManager/NetworkManager.conf
:
[main]
...
dns=none
现在,我们有两个选择:
- 手动设置系统范围的 DNS
- 使用 resolvconf 设置 DNS:
手动设置系统范围的 DNS
将所需的 DNS 服务器作为名称服务器放置在/etc/resolv.conf
:
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 1.1.1.1
使用 resolvconf 设置 DNS
如果你使用 VPN 并通过它配置了特定的 DNS 服务器,则这是首选方式
sudo ln -sfn /run/resolvconf/resolv.conf /etc/resolv.conf