在 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
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
在 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 服务器。这是本地存根解析器。当您运行命令 时
ls -l /etc/resolv.conf
,您将看到它链接到定义本地存根解析器的文件:这是正常行为。它在本地缓存 DNS 查询以进行解析。如果查询不在缓存中,那么它将查询通过 DHCP 提供的或在 Netplan 配置文件中手动定义的任何上行链路 DNS 服务器。要查看您的上行链路 DNS 服务器是什么,请运行
resolvectl status
: