UBUNTU SERVER 18.04 LTS,带 2 个 GE NIC
eno1: 172.22.1.1/20
eno2: 10.11.1.34/30
netplan yaml:
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses: [ 172.22.1.1/20 ]
gateway4: 172.22.0.1
nameservers:
addresses:
- "172.22.0.53"
routing-policy:
- to: 172.22.224.0/19
table: 211
priority: 10
- to: 192.168.201.0/24
table: 200
priority: 20
routes:
- to: 0.0.0.0/0
via: 172.22.0.254
table: 211
- to: 0.0.0.0/0
via: 172.22.0.1
table: 200
eno2:
addresses: [ 10.11.1.34/30 ]
routing-policy:
- from: 10.11.1.34
table: 222
priority: 8
- to: 10.128.0.0/16
table: 222
priority: 5
routes:
- to: 0.0.0.0/0
via: 10.11.1.33
table: 222
当我应用配置、重新启动网络或使用时netplan apply
,只有其中一个路由策略有效:
当我使用时netplan apply
:
eno1
:- 第一次,只有第一个路由策略有效。
- 第二次,只有第二个路由策略起作用。
- 第三次,只有第一个路由策略有效。
eno2
- 每次只有第二个路由策略有效。
我将 yaml 文件编写为netplan.io 示例告诉。
答案1
我不确定它是否会起作用。
这是我的建议netplan yaml
:
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses: [ 172.22.1.1/20 ]
gateway4: 172.22.0.1
nameservers:
addresses:
- "172.22.0.53"
routing-policy:
- from: 172.22.1.1
to: 172.22.224.0/19
table: 221
- from: 172.22.1.1
to: 192.168.201.0/24
table: 201
routes:
- to: 0.0.0.0/0
via: 172.22.0.254
table: 221
- to: 0.0.0.0/0
via: 172.22.0.1
table: 201
- to: 172.22.224.0/19
via: 172.22.0.254
- to: 192.168.201.0/24
via: 172.22.0.1
eno2:
addresses: [ 10.11.1.34/30 ]
routing-policy:
- from: 10.11.1.34
table: 222
routes:
- to: 0.0.0.0/0
via: 10.11.1.33
table: 222
- to: 10.128.0.0/16
via: 10.11.1.33
答案2
下面的操作适用于具有两个网卡的系统,每个网卡使用不同的网关、接口和 IP:
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses:
- 172.22.1.1/20
dhcp4: no
dhcp6: no
# addresses: [ 172.22.1.1/20 ]
# gateway4: 172.22.0.1
nameservers:
addresses: [172.22.0.53]
# - "172.22.0.53"
routes:
- to: 0.0.0.0/0
via: 172.22.0.254
table: 200
metric: 100
# table: 211
- to: 0.0.0.0/0
via: 172.22.0.1
table: 200
metric: 100
- to: 172.22.1.0/20
via: 172.22.0.1
table: 200
on-link: true
routing-policy:
- to: 172.22.224.0/19
table: 200
# table: 211
priority: 10
- to: 192.168.201.0/24
table: 200
priority: 20
eno2:
addresses:
- 10.11.1.34/30
dhcp4: no
dhcp6: no
nameservers:
addresses: [???.???.???.???]
# addresses: [ 10.11.1.34/30 ]
routes:
- to: 10.11.1.0/30
via: 10.11.1.33
table: 222
on-link: true
- to: 0.0.0.0/0
via: 10.11.1.33
table: 222
metric: 100
on-link:true
routing-policy:
- from: 10.11.1.34
table: 222
priority: 8
- to: 10.128.0.0/16
table: 222
priority: 5
运行以下命令来检查更改并查看可能的错误很有用:
sudo netplan --debug apply