将 22.04 升级到 22.10 后出现“名称解析暂时失败”

将 22.04 升级到 22.10 后出现“名称解析暂时失败”

将我的 KVM VPS 升级到 22.10 后,它们无法再解析地址。同一提供商托管的所有服务器上都存在同样的问题(我使用他们的映像安装了 22.04)。我还有其他 22.04 实例(托管在另一个提供商上),我同时将它们升级到版本 22.10,它们没有出现此问题。

$ sudo ping google.com
ping: google.com: Temporary failure in name resolution
$ resolvectl 
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 (docker0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
$ ls -la /etc/resolv.conf
lrwxrwxrwx 1 root root 37 Dec  6 19:50 /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf
$ sudo service systemd-resolved status
● systemd-resolved.service - Network Name Resolution
     Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; preset: enabled)
     Active: active (running) since Tue 2022-12-06 19:51:52 CET; 42min ago
       Docs: man:systemd-resolved.service(8)
             man:org.freedesktop.resolve1(5)
             https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers
             https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients
   Main PID: 451 (systemd-resolve)
     Status: "Processing requests..."
      Tasks: 1 (limit: 9168)
     Memory: 5.6M
        CPU: 197ms
     CGroup: /system.slice/systemd-resolved.service
             └─451 /lib/systemd/systemd-resolved

Dec 06 19:51:52 wh1 systemd[1]: Starting Network Name Resolution...
Dec 06 19:51:52 wh1 systemd-resolved[451]: Positive Trust Anchors:
Dec 06 19:51:52 wh1 systemd-resolved[451]: . IN DS 20326 8 2 e06d44b80b8f1d39a95c0b0d7c65d08458e880409bbc683457104237c7f8ec8d
Dec 06 19:51:52 wh1 systemd-resolved[451]: Negative trust anchors: home.arpa 10.in-addr.arpa 16.172.in-addr.arpa 17.172.in-addr.arpa 18.172.in-addr.arpa 19.172.in-addr.arpa 20.172.in-addr.arpa 21.172.in-addr.ar>
Dec 06 19:51:52 wh1 systemd-resolved[451]: Using system hostname 'wh1'.
Dec 06 19:51:52 wh1 systemd[1]: Started Network Name Resolution.
$ 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 .

手动输入nameserver 1.1.1.1可以/etc/resolv.conf暂时解决问题,直到下次重新启动时文件被重置。升级之前,使用 22.04 版本,服务器运行正常。

这是我工作的 22.10 实例的输出,其中实际上列出了 DNS 服务器:

$ resolvectl 
Global
     Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=allow-downgrade/supported
  resolv.conf mode: stub
Current DNS Server: 46.38.252.230
       DNS Servers: 46.38.252.230 46.38.225.230 2a03:4000:0:1::e1e6 2a03:4000:8000::fce6
    
Link 2 (eth0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=allow-downgrade/supported
    
Link 27 (docker0)
Current Scopes: none
     Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=allow-downgrade/supported

我发现了几篇类似的帖子,但没有一个能解决我的问题。

编辑:我刚刚发现,在 DNS 解析不起作用的服务器上netplan没有安装,而在正常工作的服务器上安装了。我真的不知道 Ubuntu 中的网络是如何工作的,但也许这可能是罪魁祸首。我该如何修复它?

答案1

我按照这里的简短指南(加上一点直觉)设法解决了这个问题: https://gist.github.com/mss/7a8e048dd51e5ef928039f1450ba8f31

从 ifupdown 迁移到 netplan。

# Tested on an upgraded Ubuntu 20.04
apt install netplan.io
systemctl unmask systemd-networkd.service
systemctl unmask systemd-resolved.service
ENABLE_TEST_COMMANDS=1 netplan migrate
netplan try
reboot
apt purge ifupdown resolvconf
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

相关内容