在我定义静态 IP 后,我的网络设置出现了问题。我花了一段时间才让它恢复正常,但现在出现了一些奇怪的症状。其中之一就是无法再解析 DNS。我可以ping google.com
毫无问题地 ping microsoft.com、godaddy.com 甚至 8.8.8.8 都会出现问题ping: connect: Network is unreachable
该机器是 I7、32Gb 内存,运行 Ubuntu 服务器 20.04,大部分是无头的。使用 ssh。
我的网络上的其他设备没有这个问题。
$ ifconfig
docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:22:f6:ee:c8 txqueuelen 0 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.101 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 2a02:14c:805f:ffc5:1ac0:4dff:fe41:3e93 prefixlen 64 scopeid 0x0<global>
inet6 fe80::1ac0:4dff:fe41:3e93 prefixlen 64 scopeid 0x20<link>
ether 18:c0:4d:41:3e:93 txqueuelen 1000 (Ethernet)
RX packets 331527 bytes 83760648 (83.7 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 182973 bytes 52213897 (52.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 16 memory 0x53200000-53220000
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 209338 bytes 12397801 (12.3 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 209338 bytes 12397801 (12.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我的 /etc/resolv.conf 每次重启都会被清理到这个状态:
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# 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 must 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
$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1
/etc/netplan/00-installer-config.yaml
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses: ['192.168.1.101/24']
nameservers:
addresses: [8.8.8.8, 8.8.4.4, 192.168.1.1, 212.143.0.1, 194.90.0.1, '2a02:148::1', '2a02:149::>
知道哪里出了问题以及如何解决吗?
顺便说一句,ping IP6 地址确实有效!
答案1
您的路由表中应该有一个类似这样的条目 smt。
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 [your gateway] 255.255.255.0 U 0 0 0 iface
这是一个示例 netplan conf
network:
version: 2
renderer: networkd
ethernets:
enp3s0:
addresses:
- 10.10.10.2/24
gateway4: 10.10.10.1
nameservers:
search: [mydomain, otherdomain]
addresses: [10.10.10.1, 1.1.1.1]
尝试将网关添加到您的 netplan conf 和 netplan apply。