如何在最小网络设置下更改 DNS

如何在最小网络设置下更改 DNS

我如何更换 DNS?除了systemd-networkdwpa_supplicant无线之外,我没有使用网络管理器wpa_cli。如果重要的话,我在使用 Arch Linux。

尽管我可以将 DNS 添加到我的配置中、systemctl restart systemd-resolved覆盖/etc/resolv.conf(符号链接到/run/systemd/resolve/resolv.conf)或重新启动,但不知何故将默认 ISP DNS 添加到/etc/resolv.conf。有谁知道为什么,或者如何解决这个问题以仅使用我配置的 DNS?

当我编辑/etc/resolv.conf为仅包含

nameserver 208.67.222.222
nameserver 208.67.220.220 

并运行systemctl restart systemd-resolved或重新启动,默认的 ISP DNS 将被覆盖,如下cat /etc/resolv.conf所示:

# This file is managed by systemd-resolved(8). Do not edit.
#
# Third party programs must not access this file directly, but
# only through the symlink at /etc/resolv.conf. To manage
# resolv.conf(5) in a different way, replace the symlink by a
# static file or a different symlink.

nameserver 75.75.75.75
nameserver 192.168.1.1
nameserver 208.67.222.222
# Too many DNS servers configured, the following entries may be ignored.
nameserver 75.75.76.76
nameserver 208.67.220.220

如下所述man resolved.conf,我确保只有一个配置文件,/etc/systemd/resolved.conf.d/resolv.conf包含

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.
#
# See resolved.conf(5) for details

[Resolve]
DNS=208.67.222.222 208.67.220.220
#FallbackDNS=8.8.8.8 8.8.4.4 2001:4860:4860::8888 2001:4860:4860::8844
#LLMNR=yes

并且这里的所有配置文件中没有其他定义我的 DNS 的文件:

/etc/systemd/resolved.conf

/etc/systemd/resolved.conf.d/*.conf

/run/systemd/resolved.conf.d/*.conf

/usr/lib/systemd/resolved.conf.d/*.conf

我也不相信我正在运行任何 dhcpcd 或 netctl 服务,并且systemctl | grep dhcpcd,并且systemctl | grep netctl没有返回任何内容。

答案1

我通过将以下内容添加到我的网络配置文件中来解决了此问题/etc/systemd/network/*.network

[DHCP]
UseDNS=false

默认情况下,这是正确的,这意味着 DNS 服务器从 DHCP 网络连接中获取。如果我禁用此功能,并输入我自己的静态 DNS(即 OpenDNS),那么我可以确保只使用我选择的 DNS。

相关内容