我已阅读有关 systemd-resolved.service https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html并学习了处理 /etc/resolv.conf 的四种模式。
- /run/systemd/resolve/stub-resolv.conf
- /usr/lib/systemd/resolv.conf
- /run/systemd/resolve/resolv.conf
- /etc/resolv.conf 可能由其他包管理
我已经阅读了好几遍,但仍然对如何确定作为普通用户应该选择 /etc/resolv.conf 的哪种模式感到困惑。
例如,我尝试添加一些自定义 dns 服务器,所以,
- 在/etc/systemd/resolved.conf 中添加DNS=8.8.8.8 8.8.4.4 并检查/run/systemd/resolve/resolv.conf 中是否存在8.8.8.8 和8.8.4.4。
- 如果将 /run/systemd/resolve/resolv.conf 符号链接到 /etc/resolv.conf,则 /run/systemd/resolve/resolv.conf 中将不存在 8.8.8.8 和 8.8.4.4。
更新1:
test@instance-1:~$ cat /run/systemd/resolve/resolv.conf
...
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 8.8.8.8
nameserver 8.8.4.4
test@instance-1:/etc$ sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
test@instance-1:/etc$ ls -alh /etc/resolv.conf
lrwxrwxrwx 1 root root 32 Mar 18 07:22 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf
test@instance-1:/etc$ sudo reboot
test@instance-1:~$ cat /etc/resolv.conf
domain c.prime-poetry-197705.internal
search c.prime-poetry-197705.internal. google.internal.
nameserver 169.254.169.254
test@instance-1:~$ cat /run/systemd/resolve/resolv.conf
domain c.prime-poetry-197705.internal
search c.prime-poetry-197705.internal. google.internal.
nameserver 169.254.169.254
test@instance-1:~$ ls -alh /etc/resolv.conf
lrwxrwxrwx 1 root root 32 Mar 18 07:22 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf
更新 2:来自 /etc/resolv.conf 的符号链接
test@instance-1:~$ sudo ln -sf /etc/resolv.conf /run/systemd/resolve/resolv.conf
test@instance-1:~$ ls -alh /run/systemd/resolve/resolv.conf
lrwxrwxrwx 1 root root 16 Mar 18 07:51 /run/systemd/resolve/resolv.conf -> /etc/resolv.conf
test@instance-1:~$ sudo reboot
test@instance-1:~$ ls -alh /run/systemd/resolve/resolv.conf
-rw-r--r-- 1 systemd-resolve systemd-resolve 603 Mar 18 07:52 /run/systemd/resolve/resolv.conf