Basic VLAN switching
本页概述 MikroTik RouterOS 上的基本 VLAN 交换配置,涵盖配备 Marvell Prestera 和 RTL8367/CRS 系列交换机芯片的设备设置,包括硬件卸载 VLAN 过滤和端口配置示例。
Basic VLAN switching
许多 MikroTik 设备自带支持硬件级 VLAN 交换的内置交换机芯片。只要采用适当的配置方法,就能在使用 VLAN 时实现线速性能。由于不同型号的配置方法各不相同,本指南侧重于使用不同的设备设置一个基本的干道/接入端口,以及从干道端口分出管理端口,并采用正确的配置以获得最佳性能并充分利用可用的硬件组件。

配备 Marvell Prestera 交换芯片以及 RTL8367、88E6393X、88E6191X、88E6190、MT7621、MT7531 和 EN7523 交换机芯片的 MikroTik 设备
/interface/bridge
add name=bridge1 frame-types=admit-only-vlan-tagged
/interface/bridge/port
add bridge=bridge1 interface=ether1 frame-types=admit-only-vlan-tagged
add bridge=bridge1 interface=ether2 pvid=20 frame-types=admit-only-untagged-and-priority-tagged
add bridge=bridge1 interface=ether3 pvid=30 frame-types=admit-only-untagged-and-priority-tagged
/interface/bridge/vlan
add bridge=bridge1 tagged=ether1 vlan-ids=20
add bridge=bridge1 tagged=ether1 vlan-ids=30
add bridge=bridge1 tagged=ether1,bridge1 vlan-ids=99
/interface/vlan
add interface=bridge1 vlan-id=99 name=MGMT
/ip/address
add address=192.168.99.1/24 interface=MGMT
/interface/bridge
set bridge1 vlan-filtering=yes
更详细的示例可以在此处找到。
信息
RTL8367、88E6393X、88E6191X、88E6190、MT7621、MT7531 和 EN7523 交换机芯片从 RouterOS v7 开始可以使用硬件卸载的 VLAN 过滤。 警告
frame-types设置为admit-all或admit-only-untagged-and-priority-tagged的网桥端口将自动作为pvidVLAN 的未标记端口添加。
CRS1xx/CRS2xx 系列交换机
/interface/bridge
add name=bridge1
/interface/bridge/port
add bridge=bridge1 interface=ether1
add bridge=bridge1 interface=ether2
add bridge=bridge1 interface=ether3
/interface/ethernet/switch/ingress-vlan-translation
add ports=ether2 customer-vid=0 new-customer-vid=20
add ports=ether3 customer-vid=0 new-customer-vid=30
/interface/ethernet/switch/egress-vlan-tag
add tagged-ports=ether1 vlan-id=20
add tagged-ports=ether1 vlan-id=30
add tagged-ports=ether1,switch1-cpu vlan-id=99
/interface/ethernet/switch/vlan
add ports=ether1,ether2 vlan-id=20
add ports=ether1,ether3 vlan-id=30
add ports=ether1,switch1-cpu vlan-id=99
/interface/vlan
add interface=bridge1 vlan-id=99 name=MGMT
/ip/address
add address=192.168.99.1/24 interface=MGMT
/interface/ethernet/switch
set drop-if-invalid-or-src-port-not-member-of-vlan-on-ports=ether1,ether2,ether3
更详细的示例可以在此处找到。
其他带内置交换机芯片的设备
/interface/bridge
add name=bridge1
/interface/bridge/port
add bridge=bridge1 interface=ether1
add bridge=bridge1 interface=ether2
add bridge=bridge1 interface=ether3
/interface/ethernet/switch/vlan
add ports=ether1,ether2 switch=switch1 vlan-id=20
add ports=ether1,ether3 switch=switch1 vlan-id=30
add ports=ether1,switch1-cpu switch=switch1 vlan-id=99
/interface/vlan
add interface=bridge1 vlan-id=99 name=MGMT
/ip/address
add address=192.168.99.1/24 interface=MGMT
/interface/ethernet/switch/port
set ether1 vlan-mode=secure vlan-header=add-if-missing
set ether2 vlan-mode=secure vlan-header=always-strip default-vlan-id=20
set ether3 vlan-mode=secure vlan-header=always-strip default-vlan-id=30
set switch1-cpu vlan-header=leave-as-is vlan-mode=secure
更详细的示例可以在此处找到。
:::info Applicability & Scope 此配置适用于 RouterBOARD 系列设备(RB4xx、RB9xx、RB2011、RB3011、hAP、hEX、cAP 等)。
并非所有带交换机芯片的设备都支持硬件级 VLAN 交换。如果设备支持 VLAN table,则可以使用内置交换机芯片。使用 /interface/ethernet/switch/print 或兼容性表检查您的芯片能力。
:::
:::warning Hardware Limitations & Configuration Rules
- 多个交换机芯片: 在具有多个芯片的设备(例如 RB2011、RB3011、RB1100)上,VLAN 流量仅在同一芯片上的端口之间进行硬件交换。跨不同芯片桥接端口意味着 VLAN 将不会在硬件层面进行过滤。要绕过此限制,可以在芯片之间连接一条物理电缆,或使用 Bridge VLAN Filtering(这会禁用硬件卸载)。
- QCA8337 和 Atheros8327 芯片: 您必须保留默认的
vlan-header=leave-as-is属性。交换机芯片使用default-vlan-id属性(该属性应仅应用于接入/混合端口)将未标记的入站流量分配到某个 VLAN。 - RSTP 冲突: 默认情况下,网桥接口使用
protocol-mode=rstp。在某些设备上,这会禁用硬件卸载。请查看 Bridge Hardware Offloading 部分以了解受支持的功能。 :::
其他不带内置交换机芯片的设备
可以使用 CPU 进行 VLAN 过滤;有多种方法可以做到,但强烈建议使用 bridge VLAN filtering。
/interface/bridge
add name=bridge1 frame-types=admit-only-vlan-tagged
/interface/bridge/port
add bridge=bridge1 interface=ether1 frame-types=admit-only-vlan-tagged
add bridge=bridge1 interface=ether2 pvid=20 frame-types=admit-only-untagged-and-priority-tagged
add bridge=bridge1 interface=ether3 pvid=30 frame-types=admit-only-untagged-and-priority-tagged
/interface/bridge/vlan
add bridge=bridge1 tagged=ether1 vlan-ids=20
add bridge=bridge1 tagged=ether1 vlan-ids=30
add bridge=bridge1 tagged=ether1,bridge1 vlan-ids=99
/interface/vlan
add interface=bridge1 vlan-id=99 name=MGMT
/ip/address
add address=192.168.99.1/24 interface=MGMT
/interface/bridge
set bridge1 vlan-filtering=yes
更详细的示例可以在此处找到。