近期遇到一个需求,在同一张网卡,一个网线,需要配置2个不同网段IP,特意分享下。
网络划分多个VLAN,配置如下。
已知配置的VLAN分别有(网卡为eno1):
VLAN:35 IP:10.152.20.8 网关:10.152.20.1
VLAN:390 IP:10.188.34.166 网关:10.188.34.254
需求,默认走10.152.20.8的网关,其中10.188.37.*默认使用IP10.188.34.166(增加路由)
可行的netplan多VLAN配置(注:配置格式需要严格处理,否则配置可能异常)如下:
# This is the network config written by 'subiquity'
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: false
dhcp6: false
vlans:
vlan35:
accept-ra: no
id: 35
link: eno1
vlan390:
accept-ra: no
id: 390
link: eno1
bridges:
br-mgmt:
addresses: [10.152.20.8/28]
interfaces: [vlan35]
gateway4: 10.152.20.1
parameters:
stp: false
forward-delay: 0
br-storage:
addresses: [10.188.34.166/24]
routes:
- to: 110.188.37.0/24
via: 10.188.34.254
metric: 100
interfaces: [vlan390]
parameters:
stp: false
forward-delay: 0