如何让 eth0 使用全局 DNS 设置?

如何让 eth0 使用全局 DNS 设置?

无论我尝试什么,eth0DHCP DNS 设置都没有任何变化。

这是我得到的结果sudo resolvectl status --no-pager

Global
       LLMNR setting: no                  
MulticastDNS setting: no                  
  DNSOverTLS setting: yes                 
      DNSSEC setting: yes                 
    DNSSEC supported: yes                 
  Current DNS Server: 1.1.1.1             
         DNS Servers: 1.1.1.1             
                      1.0.0.1             
                      2606:4700:4700::1111
                      2606:4700:4700::1001
          DNS Domain: ~.                  

Link 2 (eth0)
      Current Scopes: DNS        
DefaultRoute setting: yes        
       LLMNR setting: yes        
MulticastDNS setting: no         
  DNSOverTLS setting: yes        
      DNSSEC setting: yes        
    DNSSEC supported: yes        
  Current DNS Server: 192.168.4.1
         DNS Servers: 192.168.4.1

Link 3 (wlan0)
      Current Scopes: none
DefaultRoute setting: no  
       LLMNR setting: yes 
MulticastDNS setting: no  
  DNSOverTLS setting: yes 
      DNSSEC setting: yes 
    DNSSEC supported: yes 

Link 4 (docker0)
      Current Scopes: none
DefaultRoute setting: no  
       LLMNR setting: yes 
MulticastDNS setting: no  
  DNSOverTLS setting: yes 
      DNSSEC setting: yes 
    DNSSEC supported: yes 

请注意,eth0正在使用192.168.4.1

我曾尝试添加:

[Network]
UseDNS=false
[DHCP]
UseDNS=false
[DHCPv4]
UseDNS=false
[DHCPv6]
UseDNS=false
[IPv6AcceptRA]
UseDNS=false

/etc/systemd/network/eth0.network/etc/systemd/networkd.conf/etc/systemd/resolved.conf

我尝试过以下任意组合:

  • sudo resolvectl reset-server-features
  • sudo resolvectl revert eth0
  • sudo systemd-resolve --set-dns=1.1.1.1 --interface=eth0
  • sudo resolvectl dns eth0 1.1.1.1
  • sudo systemctl daemon-reload
  • sudo systemctl restart systemd-networkd
  • sudo systemctl restart systemd-resolved
  • sudo resolvectl flush-caches --no-pager
  • sudo resolvectl status --no-pager
  • sudo systemd-resolve --statistics

这是当前的cat /etc/systemd/resolved.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.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details

[DHCP]
UseDNS=false

[DHCPv4]
UseDNS=false

[DHCPv6]
UseDNS=false

[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#DNSSEC=no
#DNSOverTLS=no
#MulticastDNS=no
#LLMNR=no
#Cache=no-negative
#DNSStubListener=yes
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no
DNS=1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001
DNSSEC=true
DNSOverTLS=true

我错过了什么?我浏览了数百个标签并进行了互联网搜索,但我还是找不到。

系统是Ubuntu 20.10 (GNU/Linux 5.8.0-1029-raspi aarch64

答案1

似乎这样做sudo systemctl restart systemd-networkd会重置可通过应用的 DNS 配置sudo resolvectl dns eth0 1.1.1.1

因此,配置文件更改后应进行重新启动,API 更改后应进行刷新和状态检查。

话虽如此,我能得到的最好的信息如下:

Link 2 (eth0)
      Current Scopes: DNS                 
DefaultRoute setting: no                  
       LLMNR setting: no                  
MulticastDNS setting: no                  
  DNSOverTLS setting: yes                 
      DNSSEC setting: yes                 
    DNSSEC supported: yes                 
  Current DNS Server: 192.168.4.1         
         DNS Servers: 1.1.1.1             
                      1.0.0.1             
                      2606:4700:4700::1111
                      2606:4700:4700::1001
                      192.168.4.1         
          DNS Domain: ~.      

它仍然具有Current DNS Server作为 DHCP DNS 服务器的功能。


通过执行以下操作可以更新 eth0:

sleep 1
sudo ifdown "$interface"
sleep 1
sudo ifup "$interface"
sleep 1

相关内容