答案1
在 Ubuntu Server 22.04 中,网络由 systemd-networkd(而不是 NetworkManager)管理。使用 Netplan 配置网络设置
DNS 名称解析由名为 systemd-resolved 的服务提供。它通过 D-Bus 接口、解析 NSS 服务 (nss-resolve(8)) 和 127.0.0.53 上的本地 DNS 存根侦听器提供 DNS 解析。如果您运行该命令,cat /etc/resolv.conf
您会看到它将 127.0.0.53 列为 DNS 服务器。这是本地存根解析器。
$ cat /etc/resolv.conf
# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0 trust-ad
search localdomain
当您运行该命令时ls -l /etc/resolv.conf
,您会看到它链接到定义本地存根解析器的文件:
$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 37 Mar 20 10:16 /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf
这是正常行为。它会在本地缓存 DNS 查询以进行解析。如果查询不在缓存中,则它将查询通过 DHCP 提供或在 Netplan 配置文件中手动定义的任何上行 DNS 服务器。要查看您的上行 DNS 服务器,请运行resolvectl status
:
$ resolvectl status
Global
Protocols: -LLMNR -mDNS -DNSOverTLS
DNSSEC=no/unsupported
resolv.conf mode: stub
Link 2 (eth0)
Current Scopes: none
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS
DNSSEC=no/unsupported
Link 3 (eth1)
Current Scopes: none
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS
DNSSEC=no/unsupported
Link 4 (bond0)
Current Scopes: DNS
Protocols: +DefaultRoute +LLMNR -mDNS
-DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.10.1
DNS Servers: 192.168.10.1
DNS Domain: localdomain