我目前在我的 Ubuntu 18.04 服务器上访问互联网时遇到问题。服务器启用了两个 NIC。我可以 ping 默认网关和内部 IP,但无法 ping 任何外部 IP。我检查了防火墙,看到 ping 被允许并且正在发出,但我没有收到任何回复。我在下面包含了我的网络配置。谢谢你。
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:81:04:0d brd ff:ff:ff:ff:ff:ff
inet 172.18.248.27/24 brd 172.18.248.255 scope global ens160
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe81:40d/64 scope link
valid_lft forever preferred_lft forever
3: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:50:56:81:76:4c brd ff:ff:ff:ff:ff:ff
inet 172.18.254.27/24 brd 172.18.254.255 scope global ens192
valid_lft forever preferred_lft forever
inet6 fe80::250:56ff:fe81:764c/64 scope link
valid_lft forever preferred_lft forever
从界面 Pinging 到 Google 强制,
ping -I ens160 8.8.8.8
PING 8.8.8.8 (8.8.8.8) from 172.18.248.27 ens160: 56(84) bytes of data.
--- 8.8.8.8 ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4092ms
正常 ping 到 Google,
ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
--- 8.8.8.8 ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 5104ms
Ping 到 DG,
ping 172.18.248.254
PING 172.18.248.254 (172.18.248.254) 56(84) bytes of data.
64 bytes from 172.18.248.254: icmp_seq=1 ttl=64 time=0.767 ms
64 bytes from 172.18.248.254: icmp_seq=2 ttl=64 time=0.800 ms
^C
--- 172.18.248.254 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1024ms
rtt min/avg/max/mdev = 0.767/0.783/0.800/0.032 ms
到 Google 的跟踪路径,
tracepath 8.8.8.8
1?: [LOCALHOST] pmtu 1500
1: ??? 4.654ms
1: ??? 4.709ms
2: no reply
3: no reply
4: no reply
5: no reply
6: no reply
^C
路线,
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.18.248.254 0.0.0.0 UG 0 0 0 ens160
172.18.248.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
172.18.254.0 0.0.0.0 255.255.255.0 U 0 0 0 ens192
IP路由列表,
default via 172.18.248.254 dev ens160 proto static
172.18.248.0/24 dev ens160 proto kernel scope link src 172.18.248.27
172.18.254.0/24 dev ens192 proto kernel scope link src 172.18.254.27
/etc/netplan 文件,
network:
ethernets:
ens160:
addresses:
- 172.18.248.27/24
gateway4: 172.18.248.254
nameservers:
addresses:
- 8.8.8.8
ens192:
addresses:
- 172.18.254.27/24
gateway4: 172.18.254.254
nameservers:
addresses:
- 8.8.8.8
version: 2
编辑:
我想我可能已经找到了。这是无法访问 Internet 的机器 (M1) 上 netstat -r 的输出。
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default 172.18.248.254 0.0.0.0 UG 0 0 0 ens160
default 172.18.254.254 0.0.0.0 UG 0 0 0 ens192
172.18.248.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
172.18.254.0 0.0.0.0 255.255.255.0 U 0 0 0 ens192
这是同一子网中可以访问互联网的机器 (M2) 上的 netstat -r 命令。
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default _gateway 0.0.0.0 UG 0 0 0 ens160
172.18.248.0 0.0.0.0 255.255.255.0 U 0 0 0 ens192
172.18.254.0 0.0.0.0 255.255.255.0 U 0 0 0 ens160
所以我相信这是内核路由中的错误配置。有谁知道我如何纠正它以模仿 M2 的配置?