我有两个接口(eth0 和 eth1),它们位于它们自己的子网(11.0.0.0/24 和 11.0.1.0/24)和网关(11.0.0.1 和 11.0.1.1)中。我想以这样一种方式配置 ECMP,以使来自我的主机的所有流量均等地分布在两个接口之间。我使用以下 ip 命令让它工作:
# Setting up default gateways for the two interfaces
ip route add 11.0.0.0/24 dev eth0 src 11.0.0.4 table rt1
ip route add default via 11.0.0.1 table rt1
ip route add 11.0.1.0/24 dev eth1 src 11.0.1.4 table rt2
ip route add default via 11.0.1.1 table rt2
# Adding routes to the main table
ip route add 11.0.0.0/24 dev eth0 src 11.0.0.4
ip route add 11.0.1.0/24 dev eth1 src 11.0.1.4
# Setting default route
ip route add default via 11.0.0.1
# Adding routes
ip rule add from 11.0.0.4 table rt1
ip rule add from 11.0.1.4 table rt2
# Adding ECMP route
ip route add default scope global nexthop via 11.0.0.1 dev eth0 weight 1 nexthop via 11.0.1.1 dev eth1 weight 1
我正在尝试使用 Ubuntu 18.04 LTS 的 cloud-init 和 netplan 复制此设置。这是我正在使用的配置:
#cloud-config
network:
version: 2
ethernets:
eth0:
dhcp4: true
dhcp4-overrides:
route-metric: 100
dhcp6: false
match:
driver: hv_netvsc
macaddress: 00:22:48:20:af:fa
set-name: eth0
gateway4: 11.0.0.1
routes:
- to: 11.0.0.4/32
via: 11.0.0.1
table: 101
routing-policy:
- from: 11.0.0.4/32
table: 101
eth1:
dhcp4: true
dhcp4-overrides:
route-metric: 200
dhcp6: false
match:
driver: hv_netvsc
macaddress: 00:22:48:20:ab:1c
set-name: eth1
gateway4: 11.0.1.1
routes:
- to: 11.0.1.4/32
via: 11.0.1.1
table: 102
routing-policy:
- from: 11.0.1.4/32
table: 102
runcmd:
- [sh, -c, 'echo "Adding route tables"']
- [sh, -c, 'echo "101 rt1" >> /etc/iproute2/rt_tables']
- [sh, -c, 'echo "102 rt2" >> /etc/iproute2/rt_tables']
- [sh, -c, 'ip route add default scope global nexthop via 11.0.0.1 dev eth0 weight 1 nexthop via 11.0.1.1 dev eth1 weight 1']
我可能做错了一些非常简单和基本的事情,但这是我第一次使用网络和 cloud-init,所以我无法弄清楚我做错了什么。谢谢你的帮助!