我正在尝试将 DNS 设置为 1.1.1.1。我已编辑/etc/systemd/resolved.conf
以包含:
[Resolve]
DNS=1.1.1.1
FallbackDNS=8.8.8.8
但似乎该设置正在每个界面上被覆盖。解析器的输出:
Global
Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
resolv.conf mode: foreign
Current DNS Server: 1.1.1.1
DNS Servers: 1.1.1.1
Fallback DNS Servers: 8.8.8.8
DNS Domain: ~.
Link 2 (enp6s0)
Current Scopes: DNS
Protocols: +DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.0.1
DNS Servers: 192.168.0.1
我怎样才能让 enp6s0 不覆盖全局设置,或者只是将其设置为 1.1.1.1?
答案1
我找到了解决这个问题的方法。我还运行 NetworkManager,看起来它覆盖了该接口的 DNS 设置。编辑 DNS 设置nmtui
并设置Ignore automatically obtained DNS parameters
修复了该问题。
答案2
我想你已经遇到过这个:
没有域=~。 solved.conf(5) 中的选项,systemd-resolved 可能会使用每个链接的 DNS 服务器,如果其中任何一个设置了 Domains=~。在每个链接配置中。
这似乎确实发生在你的案例中。
看来解决方案是添加Domains=~.
到/etc/systemd/resolved.conf
:
[Resolve]
DNS=1.1.1.1
FallbackDNS=8.8.8.8
Domains=~.
这resolved.conf 的手册页可能有助于解释为什么会发生这种情况:
The domains prefixed with "~" are called "route-only
domains". All domains listed here (both search domains and
route-only domains after removing the "~" prefix) define a
search path that preferably directs DNS queries to this
interface. This search path has an effect only when suitable
per-link DNS servers are known. Such servers may be defined
through the DNS= setting (see above) and dynamically at run
time, for example from DHCP leases. If no per-link DNS
servers are known, route-only domains have no effect.
Use the construct "~." (which is composed from "~" to
indicate a route-only domain and "." to indicate the DNS
root domain that is the implied suffix of all DNS domains) to
use the DNS servers defined for this link preferably for all
domains.
似乎正在发生的情况是 DHCP 服务器告诉您的系统为所有域使用这些 DHCP 服务器,并且您的静态配置是不是做同样的事情,意味着它被覆盖。