VLAN/Hardware Switch
VLAN/Hardware Switch
功能介绍
VLAN/Hardware Switch 是一个虚拟交换机接口,它将不同的物理接口组合在一起,以便 FortiGate 可以将这些成员接口组合成单个接口。部分支持此接口的 FortiGate 型号有一个默认的硬件交换接口,称为 internal 或 lan,VLAN/Hardware Switch 可以被硬件级别的芯片支持。
连接到同一 VLAN/Hardware Switch 的接口,类似于位于同一广播域中的同一物理交换机上一样。接口成员可以从 VLAN/Hardware Switch 中移除并分配给另一个交换机或用作独立物理接口。
VLAN/Hardware 与 Software Switch 的区别
| 功能 | VLAN/Hardware switch | Software switch |
|---|---|---|
| 转发 | 数据包由设备硬件交换机或 SPU 在硬件层面处理 | 数据包由 CPU 处理 |
| STP | 支持 | 不支持 |
| 无线 SSIDs | 不支持 | 支持 |
| 交换接口互访 | 默认允许 | 默认允许,可以通过策略控制 |
VLAN Switch 与 Hardware Switch 的区别
60F、80F、100F、200F 等具有硬件交换模块的型号,通过内部硬件交换机创建的交换接口为 VLAN Switch。这些型号的设备一般在默认配置下会存在一个名称为 lan 或 Internal 的 VLAN Switch 接口,交换接口成员默认包含硬件交换模块中的成员接口,这些接口可以从预置的交换接口中取出,变为普通物理口。
40F、300E、400E、1100E、2200E、3600E、3980E、400F、600F、1800F、2600F、3000F、4400F 等具有硬件交换模块的型号,通过内部硬件交换机创建的交换接口为 Hardware Switch。
VLAN Switch 接口可以直接在接口下配置 VLAN ID,同时配置 IP 后,可以直接将 VLAN Switch 配置为 VLAN Interface(携带 VLAN Tag),实现接口成员同属于该 VLAN Interface 的效果,而无需在 VLAN Switch 接口上再配置 VLAN 接口,而 Hardware Switch 无法配置 VLAN ID,想实现上述效果,必须在 Hardware Switch 上配置 VLAN Interface。
除此之外,VLAN Switch 与 Hardware Switch 这两种交换接口在功能使用上没有差别。
配置 VLAN/Hardware Switch
创建/编辑接口
在 SoC 平台(如 40F、60F、80F、100F、200F 等)默认配置下会存在一个名称为 lan 或 Internal 的 VLAN Switch 接口,编辑该接口,交换接口成员默认包含硬件交换模块中的成员接口,这些接口可以从预置的交换接口中取出,变为普通物理口,也可将硬件交换模块的接口加入该交换接口,如下 FortiGate101F 所示。
重要
将物理口加入 Switch 接口时,接口需要清除 IP 地址(配置为 0.0.0.0/0),且不能被其他功能引用。

创建新的 VLAN/Hardware Switch,进入“网络 → 接口”页面,新建接口。

选择类型为“VLAN 交换/硬件交换”,如下图所示为 FortiGate601F,交换接口为“硬件交换”,并添加或删除接口成员。

通过 CLI 删除 VLAN/Hardware Switch 接口。
config system virtual-switch edit "internal" config port delete internal2 delete internal7 ... end next end通过 CLI 添加 VLAN/Hardware Switch 接口。
config system virtual-switch edit "internal" set physical-switch "sw0" config port edit "internal3" next edit "internal5" next edit "internal4" next edit "internal6" next end next end
在 VLAN/Hardware Switch 上使用 802.1X
网络拓扑

port3 和 port4 是硬件交换模块的一部分,配置 Hardware Switch,并将 port3 和 port4 加入,在该接口上执行 802.1X 身份验证。
配置步骤
在 FortiGate 上配置 Radius 服务器(配置方法参考 用户与认证 → Radius 认证 → Radius 认证配置与排错章节)。
在 FortiGate 上配置用于 802.1X 远程 Radius 认证的用户组(配置方法参考 用户与认证 → Radius 认证 → Radius 认证配置与排错章节)。
在 FortiGate 的“网络 → 接口”页面新建 Hardware/VLAN Switch 接口,将 port3 和 port4 加入该接口,对应 CLI 如下。
config system virtual-switch edit "switch_1" set physical-switch "sw0" config port edit "port3" next edit "port4" next end next end在 FortiGate 上配置防火墙策略允许新建的 Hardware/VLAN Switch 下的流量访问 Internet。
在 Hardware/VLAN Switch 上开启 802.1X 认证,选择创建的 Radius 认证用户组。

config system interface edit "switch_1" set vdom "vdom1" set ip 192.168.200.1 255.255.255.0 set allowaccess ping http https set type hard-switch set security-mode 802.1X set security-groups "remotegroup" set device-identification disable set role lan next end
结果验证
客户端通过 port3 或 port4 连接,并通过 802.1X 认证后,可以正常访问 Internet。
在 FortiGate 上查看 802.1X 认证端口状态。
FortiGate # diagnose sys 802-1x status Virtual switch 'switch_1' (default mode) 802.1x member status: port3: Link up, 802.1X state: authorized port4: Link up, 802.1X state: unauthorized
在 VLAN/Hardware Switch 传输带 VLAN Tag 的流量
网络需求
VLAN/Hardware Switch 也可以让 FortiGate 像二层 VLAN 交换机一样工作,进行 VLAN 交换,并可以设置一个物理口作为 Trunk 接口。支持的型号如:60F、80F、100E、100F、140E、200F、300E、400E、1100E、1800F、2600F、3500F、4200F、4400F。
网络拓扑

- FortiGate-1 上有两个硬件交换机接口(port1、port2)被分配了 VLAN 10,两个接口(port3、port4)被分配了 VLAN 20。wan1 接口被指定为 Trunk 端口,与上游的 FortiGate-2 相连。
- 上游 FortiGate-2 的子接口 VLAN10 和 VLAN20 允许 FortiGate-1 过来的带 VLAN Tag 10 和 20 的流量访问 Internet。
配置步骤
基础配置
需要确保在“config sys global”下,“virtual-switch-vlan”选项处于“enable”状态。
config sys global
set virtual-switch-vlan enable
endFortiGate-1
需要确保在“config sys global”下,“virtual-switch-vlan”选项处于“enable”状态;或在设备管理页面的“系统管理 → 设置 → 系统运行设置”中,“VLAN 交换机模式”选项处于开启状态。
config sys global set virtual-switch-vlan enable end
新建两个 VLAN/Hardware Switch,分别配置 VLAN ID 为 10 和 20,分别添加成员 port1、port2 和 port3、port4。
config system virtual-switch edit "VLAN10" set physical-switch "sw0" set vlan 10 config port edit "port1" next edit "port2" next end next edit "VLAN20" set physical-switch "sw0" set vlan 20 config port edit "port3" next edit "port4" next end next end配置两个 VLAN/Hardware Switch 接口的 IP 地址。
config system interface edit "VLAN10" set vdom "root" set ip 192.168.10.99 255.255.255.0 set allowaccess ping https ssh snmp http fgfm set type hard-switch next edit "VLAN20" set vdom "root" set ip 192.168.20.99 255.255.255.0 set allowaccess ping https ssh snmp http fgfm set type hard-switch next end配置 wan1 接口为 Trunk 口,承载 VLAN10 和 VLAN20 的流量。
config system interface edit wan1 set trunk enable next end
FortiGate-2
新建 VLAN 子接口 VLAN10 和 VLAN20,并配置 IP 地址。
config system interface edit "VLAN10" set ip 192.168.10.98 255.255.255.0 set allowaccess ping https ssh set role lan set interface "dmz" set vlanid 10 next edit "VLAN20" set ip 192.168.20.98 255.255.255.0 set allowaccess ping https ssh set role lan set interface "dmz" set vlanid 20 next end在 VLAN10 和 VLAN20 接口上分别配置 DHCP 服务器,分别为 VLAN10 和 VLAN20 的客户端分配 IP 地址。
config system dhcp server edit 0 set dns-service default set default-gateway 192.168.10.98 set netmask 255.255.255.0 set interface "VLAN10" config ip-range edit 1 set start-ip 192.168.10.100 set end-ip 192.168.10.254 next end set timezone-option default next edit 0 set dns-service default set default-gateway 192.168.20.98 set netmask 255.255.255.0 set interface "VLAN20" config ip-range edit 1 set start-ip 192.168.20.100 set end-ip 192.168.20.254 next end set timezone-option default next end配置防火墙策略允许 VLAN10 和 VLAN20 的流量访问 Internet。
config firewall policy edit 0 set name "VLAN10-out" set srcintf "VLAN10" set dstintf "wan1" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" set nat enable next edit 0 set name "VLAN20-out" set srcintf "VLAN20" set dstintf "wan1" set srcaddr "all" set dstaddr "all" set action accept set schedule "always" set service "ALL" set nat enable next end
结果验证
- FortiGate-1 下 VLAN 10 和 VLAN 20 的 PC 均可以通过 FortiGate-2 分别获取到 VLAN10 和 VLAN20 分配的 IP 地址。
- FortiGate-1 下 VLAN 10 和 VLAN 20 的 PC 均可以 Ping 通 FortiGate-1 的 VLAN/Hardware Switch 接口 IP。
- FortiGate-1 下 VLAN 10 和 VLAN 20 的 PC 均可以 Ping 通 FortiGate-2 的 VLAN 子接口 IP。
- FortiGate-1 下 VLAN 10 和 VLAN 20 的 PC 均可以正常访问 Internet,流量在 FortiGate-1 和 FortiGate-2 之间携带对应的 VLAN Tag。