我正在尝试向 Amazon EC2 上的 Ubuntu 18.04 实例添加第二个网络接口。我遵循本指南来自亚马逊关于如何操作的说明,并添加了一个 /etc/netplan/51-eth1.yaml 文件,内容如下:
network:
version: 2
renderer: networkd
ethernets:
eth1:
addresses:
- 172.31.10.13/20
dhcp4: no
routes:
- to: 0.0.0.0
via: 172.31.0.1
scope: link
table: 1001
routing-policy:
- from: 172.31.10.13
table: 1001
所以我的路由表现在如下所示:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.31.0.1 0.0.0.0 UG 100 0 0 eth0
172.31.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth1
172.31.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
172.31.0.1 0.0.0.0 255.255.255.255 UH 100 0 0 eth0
但是,使用 ping -I ping 同一子网上的地址只能从 eth1 接口进行。我确实看到回复正确到达 eth0,但操作系统似乎出于某种原因忽略了它们。在 eth0 上运行 ping 并在同一接口上运行 tcpdump,我得到了以下输出:
PING 172.31.5.193 (172.31.5.193) from 172.31.10.197 eth0: 56(84) bytes of data.
06:00:15.186249 02:bb:3e:8f:3f:1c > 02:29:0b:80:74:b4, ethertype IPv4 (0x0800), length 98: 172.31.10.197 > 172.31.5.193: ICMP echo request, id 3538, seq 1, length 64
06:00:15.186635 02:29:0b:80:74:b4 > 02:bb:3e:8f:3f:1c, ethertype IPv4 (0x0800), length 98: 172.31.5.193 > 172.31.10.197: ICMP echo reply, id 3538, seq 1, length 64
06:00:16.201069 02:bb:3e:8f:3f:1c > 02:29:0b:80:74:b4, ethertype IPv4 (0x0800), length 98: 172.31.10.197 > 172.31.5.193: ICMP echo request, id 3538, seq 2, length 64
06:00:16.201513 02:29:0b:80:74:b4 > 02:bb:3e:8f:3f:1c, ethertype IPv4 (0x0800), length 98: 172.31.5.193 > 172.31.10.197: ICMP echo reply, id 3538, seq 2, length 64
^C
--- 172.31.5.193 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1030ms
因此所有地址都是正确的,但数据包仍被视为丢失。接口上的 TCP 连接也发生同样的情况 - SYN-ACK 到达但被忽略。我已验证 iptables 规则默认被接受,并且不存在其他规则。知道这里出了什么问题吗?