我有两个接口,它们都有一个公共 IP 地址。其中一个 (eth0) 是主要的,另一个 (eth1) 是次要的。我正在尝试通过 netplan + iproute2 设置它。当我使用 Ubuntu 18.04 时,一切正常。
/etc/iproute2/rt_tables:
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
801 801
800 800
我的网络计划配置是这样的:
network:
version: 2
ethernets:
eth1:
addresses:
- 10.0.2.10/24
gateway4: 10.0.2.1
mtu: 1500
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
routes:
- to: 0.0.0.0/0
via: 10.0.2.1
metric: 50
table: 800
routing-policy:
- from: 10.0.2.10
table: 800
priority: 100
eth0:
addresses:
- 10.0.1.10/24
mtu: 1500
gateway4: 10.0.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
routes:
- to: 0.0.0.0/0
via: 10.0.1.1
metric: 100
table: 801
routing-policy:
- from: 10.0.1.10
table: 801
priority: 200
自 Ubuntu 22.04(或更早版本)以来,该gateway4
属性已被弃用并且不再使用。升级到 Ubuntu 22.04 后,我删除了gateway4
属性。但现在不行了
network:
version: 2
ethernets:
eth1:
addresses:
- 10.0.2.10/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
routes:
- metric: 50
to: 0.0.0.0/0
via: 10.0.2.1
table: 800
routing-policy:
- from: 10.0.2.10
table: 800
priority: 100
eth0:
addresses:
- 10.0.1.10/24
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
routes:
- metric: 100
to: 0.0.0.0/0
via: 10.0.1.1
table: 801
routing-policy:
- from: 10.0.1.10
table: 801
priority: 200
而且,在netplan apply
我尝试之后route -n
,我没有看到任何网关! netplan 或 iproute2 是否损坏或者我需要更改一些配置?