我有一个虚拟接口,并且启用了 802.1q。当我在 netplan 中为我的接口设置一个 vlan 时,它可以工作,但是当我添加第二个额外的 vlan 时,只有文件中的最后一个 vlan 可以工作,前面的 vlan 则不行。以下是配置:
network:
version: 2
renderer: networkd
ethernets:
ens0:
match:
name: ens160
vlans:
vlan.45:
id: 45
link: ens0
dhcp4: no
addresses: [ 10.0.45.11/24 ]
gateway: 10.0.45.1
nameservers:
search: [ domain.local ]
addresses: [ 8.8.8.8 ]
vlan.110:
id: 110
link: ens0
dhcp4: no
addresses: [ 10.0.11.103/24 ]
gateway: 10.0.11.1
nameservers:
search: [ domain.local ]
addresses: [ 10.0.11.18 ]
答案1
以下步骤可让我在一个物理接口上定义两个 VLAN:
network:
version: 2
ethernets:
ens3:
addresses:
- 192.168.122.201/24
gateway4: 192.168.122.1
nameservers:
addresses: [192.168.122.1]
ens8: {}
vlans:
vlan.101:
id: 101
link: ens8
addresses: [192.168.101.1/24]
vlan.102:
id: 102
link: ens8
addresses: [192.168.102.1/24]
请注意,vlan
部分与键的缩进级别相同ethernets
。两者都包含在内network
。
ip link
显示结果:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:e4:bc:6f brd ff:ff:ff:ff:ff:ff
3: ens8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:7e:d5:19 brd ff:ff:ff:ff:ff:ff
4: vlan.101@ens8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:7e:d5:19 brd ff:ff:ff:ff:ff:ff
5: vlan.102@ens8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 52:54:00:7e:d5:19 brd ff:ff:ff:ff:ff:ff