我有一组 Ubuntu 18.04.5 LTS 服务器,每个服务器有两个接口。eno1 - 1g 管理接口 eno5 - 10g 数据接口
两个接口都位于同一个 L2 子网 (10.98.16.0/22)。我的问题是我无法使用 eno5 (10g) 接口来 ping 其他 10g 接口。因此,类似操作ping 10.98.17.11 -I eno5
会失败,但如果我使用默认的 eno1 接口,我就可以 ping 同一个地址。
我能够使用以下命令修复此问题:
# Add new routing table
echo 100 t1 >> /etc/iproute2/rt_tables
echo 101 t2 >> /etc/iproute2/rt_tables
#Add routes to tables
ip route add 10.98.16.0/22 dev eno1 src 10.98.17.1 table t1
ip route add table t1 default via 10.98.16.1 dev eno1
ip route add 10.98.16.0/22 dev eno5 src 10.98.17.11 table t2
ip route add table t2 default via 10.98.16.1 dev eno5
# Add rules to routing tables
ip rule add table t1 from 10.98.17.1
ip rule add table t2 from 10.98.17.11
~ ping 10.98.17.13 -I eno5
PING 10.98.17.13 (10.98.17.13) from 10.98.17.11 eno5: 56(84) bytes of data.
64 bytes from 10.98.17.13: icmp_seq=1 ttl=64 time=0.157 ms
但是,我希望在 Netplan 中实现这一点。我在 /etc/netplan/00-network.yaml 中使用以下内容
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses:
- 10.98.17.1/22
routes:
- metric: 100
table: 100
to: 10.98.16.0/22
via: 10.98.17.1
eno5:
addresses:
- 10.98.17.11/22
routes:
- metric: 101
table: 101
to: 10.98.16.0/22
via: 10.98.17.11
接口已配置,没有错误。但是,我无法 ping 通。如果有人知道我遗漏了什么,请告诉我!
~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.98.16.0 0.0.0.0 255.255.252.0 U 0 0 0 eno1
10.98.16.0 0.0.0.0 255.255.252.0 U 0 0 0 eno5
答案1
添加路由策略可能会有帮助
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses:
- 10.98.17.1/22
routes:
- metric: 100
table: 100
to: 10.98.16.0/22
via: 10.98.17.1
routing-policy:
- from: 10.98.17.1
table: 100