传统网桥模式
对于传统的 Linux 网桥,内核支持 VLAN 子接口形式的 VLAN。当您在多个 VLAN 上启用桥接时,您需要为每个 VLAN 配置一个网桥,并为网桥上的每个成员端口创建一个或多个 VLAN 子接口。当端口数乘以 VLAN 数变得很大时,此模式可能会在配置大小以及启动时间和运行时状态管理方面带来可扩展性挑战。
- 使用 VLAN 感知模式 网桥代替传统模式网桥。
- 如果您需要使用 PVSTP+,请使用传统模式网桥。
配置传统模式网桥
以下示例命令配置一个名为 my_bridge
的传统模式网桥,其中 swp1、swp2、swp3 和 swp4 是该网桥的成员。该示例还使用 IP 地址 10.10.10.10/24 配置网桥,以提供对网桥接口的 IP 访问。
编辑 /etc/network/interfaces
文件,然后运行 ifreload -a
命令。
...
auto swp1
iface swp1
auto swp2
iface swp2
auto swp3
iface swp3
auto swp4
iface swp4
auto my_bridge
iface my_bridge
address 10.10.10.10/24
bridge-ports swp1 swp2 swp3 swp4
bridge-vlan-aware no
...
cumulus@switch:~$ sudo ifreload -a
- 请勿将管理端口 eth0 与任何交换机端口(swp0、swp1 等)桥接。例如,如果您创建包含 eth0 和 swp1 的网桥,则它将无法工作。
- 网桥的名称必须符合 Linux 接口命名约定,并且在交换机内是唯一的。
要为网桥接口配置生成树选项,请参阅 生成树和快速生成树 - STP。
配置多个传统模式网桥
您可以配置多个网桥,将交换机划分为多个 2 层域。这使主机能够与同一域中的其他主机通信,同时将它们与其他域中的主机分隔开来。
以下示例显示了多网桥配置,其中 host-1 和 host-2 连接到网桥 A,而 host-3 和 host-4 连接到网桥 B
- host-1 和 host-2 可以相互通信
- host-3 和 host-4 可以相互通信
- host-1 和 host-2 无法与 host-3 和 host-4 通信

此示例配置在 /etc/network/interfaces
文件中如下所示
...
auto bridge-A
iface bridge-A
bridge-ports swp1 swp2
bridge-vlan-aware no
auto bridge-B
iface bridge-B
bridge-ports swp3 swp4
bridge-vlan-aware no
...
传统网桥模式下的 trunk
trunk 的标准是 802.1Q。802.1Q 规范在以太网帧中添加了一个四字节的标头,用于标识帧所属的 VLAN。
802.1Q 还将未标记的帧标识为属于本机 VLAN(大多数网络设备将其本机 VLAN 默认为 1)。在 Cumulus Linux 中
- trunk 端口是配置为发送和接收 802.1Q 标记帧的交换机端口。
- 在 trunk 端口上发送未标记(裸以太网)帧的交换机是从 trunk 端口上定义的本机 VLAN 发送的。
- 在 trunk 端口上发送标记帧的交换机正在发送到 802.1Q 标记标识的 VLAN。
- 在 trunk 端口上接收未标记(裸以太网)帧的交换机将该帧放置在 trunk 端口上定义的本机 VLAN 中。
- 在 trunk 端口上接收标记帧的交换机将该帧放置在 802.1Q 标记标识的 VLAN 中。
传统模式下的网桥没有 trunk 的概念,只有标记或未标记的帧。对于包含 200 个 VLAN 的 trunk,需要有 199 个网桥,每个网桥包含一个标记的物理接口,以及一个包含本机未标记 VLAN 的网桥。
同一 trunk 上标记帧和未标记帧的交互通常会导致不良和意外的行为。将 VLAN 1 用作本机 VLAN 的交换机可以将帧发送到将 VLAN 2 用作本机 VLAN 的交换机,从而合并这两个 VLAN 及其生成树状态。

要创建上述示例
将以下配置添加到 /etc/network/interfaces
文件
...
auto br-VLAN10
iface br-VLAN10
bridge-ports swp1.10 swp2.10
auto br-VLAN20
iface br-VLAN20
bridge-ports swp1.20 swp2.20
...
高级 VLAN 标记示例
以下高级 VLAN 标记配置显示了三台主机和两台交换机,以及连接它们的所有网桥和 bond。

- host1 使用裸以太网帧连接到网桥 br-untagged,并使用标记为 vlan100 的 802.1q 帧连接到网桥 br-tag100。
- host2 使用标记为 vlan100 的 802.1q 帧连接到网桥 br-tag100,并使用标记为 vlan120 的 802.1q 帧连接到网桥 br-vlan120。
- host3 使用标记为 vlan120 的 802.1q 帧连接到网桥 br-vlan120,并使用标记为 vlan130 的 802.1q 帧连接到网桥 v130。
- 在此示例中,bond2 承载标记帧和未标记帧。
网桥成员端口充当 802.1Q 接入端口和 trunk 端口。为了将 Cumulus Linux 与传统的 Cisco 设备进行比较
- swp1 相当于具有未标记和 vlan100 的 trunk 端口。
- swp2 相当于具有 vlan100 和 vlan120 的 trunk 端口。
- swp3 相当于具有 vlan120 和 vlan130 的 trunk 端口。
- bond2 相当于 trunk 模式下的 EtherChannel,具有未标记、vlan100、vlan120 和 vlan130。
- 网桥 br-untagged、br-tag100、br-vlan120 和 v130 相当于 SVI(交换虚拟接口)。
要创建上述配置,请编辑 /etc/network/interfaces
文件并添加如下配置
# Config for host1
# swp1 does not need an iface section unless it has a specific setting
# it will be picked up as a dependent of swp1.100
# swp1 must exist in the system to create the .1q subinterfaces
# but it is not applied to any bridge or assigned an address
auto swp1.100
iface swp1.100
# Config for host2
# swp2 does not need an iface section unless it has a specific setting
# it will be picked up as a dependent of swp2.100 and swp2.120
# swp2 must exist in the system to create the .1q subinterfaces
# but it is not applied to any bridge or assigned an address
auto swp2.100
iface swp2.100
auto swp2.120
iface swp2.120
# Config for host3
# swp3 does not need an iface section unless it has a specific setting
# it will be picked up as a dependent of swp3.120 and swp3.130
# swp3 must exist in the system to create the .1q subinterfaces
# but it is not applied to any bridge or assigned an address
auto swp3.120
iface swp3.120
auto swp3.130
iface swp3.130
# configure the bond
auto bond2
iface bond2
bond-slaves glob swp4-7
# configure the bridges
auto br-untagged
iface br-untagged
address 10.0.0.1/24
bridge-ports swp1 bond2
bridge-stp on
auto br-tag100
iface br-tag100
address 10.0.100.1/24
bridge-ports swp1.100 swp2.100 bond2.100
bridge-stp on
auto br-vlan120
iface br-vlan120
address 10.0.120.1/24
bridge-ports swp2.120 swp3.120 bond2.120
bridge-stp on
auto v130
iface v130
address 10.0.130.1/24
bridge-ports swp3.130 bond2.130
bridge-stp on
验证配置
cumulus@switch:~$ sudo mstpctl showbridge br-tag100
br-tag100 CIST info
enabled yes
bridge id 8.000.44:38:39:00:32:8B
designated root 8.000.44:38:39:00:32:8B
regional root 8.000.44:38:39:00:32:8B
root port none
path cost 0 internal path cost 0
max age 20 bridge max age 20
forward delay 15 bridge forward delay 15
tx hold count 6 max hops 20
hello time 2 ageing time 300
force protocol version rstp
time since topology change 333040s
topology change count 1
topology change no
topology change port swp2.100
last topology change port None
cumulus@switch:~$ sudo mstpctl showportdetail br-tag100 | grep -B 2 state
br-tag100:bond2.100 CIST info
enabled yes role Designated
port id 8.003 state forwarding
--
br-tag100:swp1.100 CIST info
enabled yes role Designated
port id 8.001 state forwarding
--
br-tag100:swp2.100 CIST info
enabled yes role Designated
port id 8.002 state forwarding
cumulus@switch:~$ cat /proc/net/vlan/config
VLAN Dev name | VLAN ID
Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
bond2.100 | 100 | bond2
bond2.120 | 120 | bond2
bond2.130 | 130 | bond2
swp1.100 | 100 | swp1
swp2.100 | 100 | swp2
swp2.120 | 120 | swp2
swp3.120 | 120 | swp3
swp3.130 | 130 | swp3
单个网桥不能包含同一端口的多个子接口。如果您尝试应用此配置,您将看到错误
cumulus@switch:~$ sudo brctl addbr another_bridge
cumulus@switch:~$ sudo brctl addif another_bridge swp9 swp9.100
bridge cannot contain multiple subinterfaces of the same port: swp9, swp9.100
VLAN 转换
默认情况下,Cumulus Linux 不允许与不同 VLAN ID 关联的 VLAN 子接口成为同一网桥的一部分。基本接口不与任何 VLAN ID 关联,并且不受此限制。
在某些情况下,放宽此限制很有用。例如,当两台服务器使用 VLAN trunk 连接到交换机,但两台服务器上的 VLAN 编号不一致时。您可以通过启用 sysctl net.bridge.bridge-allow-multiple-vlans
选项来桥接来自服务器的不同 VLAN ID 的两个 VLAN 子接口。从成员 VLAN 子接口进入网桥的数据包会从另一个成员 VLAN 子接口传出,并转换 VLAN ID。
以下示例启用 VLAN 转换 sysctl
cumulus@switch:~$ echo net.bridge.bridge-allow-multiple-vlans = 1 | sudo tee /etc/sysctl.d/multiple_vlans.conf
net.bridge.bridge-allow-multiple-vlans = 1
cumulus@switch:~$ sudo sysctl -p /etc/sysctl.d/multiple_vlans.conf
net.bridge.bridge-allow-multiple-vlans = 1
启用 sysctl
后,您可以将具有不同 VLAN ID 的端口添加到同一网桥。在以下示例中,交换机将从 swp10.100 进入网桥 br-mix
的数据包桥接到 swp11.200。Cumulus Linux 将 VLAN ID 从 100 转换为 200
cumulus@switch:~$ sudo brctl addif br_mix swp10.100 swp11.200
cumulus@switch:~$ sudo brctl show br_mix
bridge name bridge id STP enabled interfaces
br_mix 8000.4438390032bd yes swp10.100
swp11.200