Ubuntu server 22 因掉电重启,启动后无法正常上网。
首先检查网络配置,网线,路由器硬件正常。
尝试dns解析,失败。
$ nslookup google.com
;; communications error to 127.0.0.1#53: connection refused
dns解析异常,检查配置文件,发现resolv.conf配置文件不存在,因此判定系统服务systemd-resolved异常。
c$ cat /etc/resolv.conf
cat: resolv.conf: No such file or directory
$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Feb 2 2021 resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
启动systemd-resolved服务,网络回复正常。
$ sudo systemctl enable --now systemd-resolved.service
Created symlink /etc/systemd/system/dbus-org.freedesktop.resolve1.service → /lib/systemd/system/systemd-resolved.service.
Created symlink /etc/systemd/system/multi-user.target.wants/systemd-resolved.service → /lib/systemd/system/systemd-resolved.service.
$ cat /etc/resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad
search .
$ ping google.com
PING google.com (142.250.204.142) 56(84) bytes of data.