Remapping VLAN ID (VLAN NAT,特殊场景使用)
Remapping VLAN ID (VLAN NAT,特殊场景使用)
重要
VLAN NAT,特殊场景使用。
简介
Remapping VLAN 简单的可以理解为,透明模式下 VLAN ID 的 NAT 转换。比如数据本来在 VLAN104 中,一旦需要透明穿过 VLAN105 去访问目的主机,这个时候 FGT 可以将原本携带了 VLAN-Tag 104 的数据转换为携带 VLAN-Tag 105 的数据,进行了一个 VLAN-Tag 的替换,以便数据可以在两个 VLAN 之间通信。
重要
谁说的跨 VLAN 之间通信的数据必须经过路由器(三层设备),不,Fortigate 二层也可以!但是这个技术使用场景有限,一般用在私有云环境中的东西向流量的控制和过滤,用的比较少,了解即可。
原始网络拓扑和需求

需求:要求 PC1 和 PC2 之间虽然是相同的网段,但是要相互隔离,同时要求防火墙策略对二者进行访问控制,PC1 可以访问 PC2,但是 PC2 不能访问 PC1,同时要求 PC1 和 PC2 都可以正常的访问互联网。
解决方案拓扑

基础配置
SW:
interface GigabitEthernet0/0
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface GigabitEthernet0/1
switchport access vlan 111
switchport mode access
no shutdown
spanning-tree portfast edge
!
interface GigabitEthernet0/2
switchport access vlan 222
switchport mode access
no shutdown
spanning-tree portfast edgeInternet_R:
interface Ethernet0/1
ip address 202.100.1.179 255.255.255.0
no shutdown
ip nat outside
!
interface Ethernet0/0
ip address 192.168.1.99 255.255.255.0
no shutdown
ip nat inside
!
ip route 0.0.0.0 0.0.0.0 202.100.1.192
!
access-list 101 permit ip any any
ip nat inside source list 101 interface Ethernet0/1 overloadFortiGate:
FortiGate-VM64-KVM # config system global
FortiGate-VM64-KVM (global) # set hostname FortiGate_Transparent
FortiGate_Transparent (global) # set timezone 55
FortiGate_Transparent (global) # set language simch
FortiGate-VM64-KVM (global) # end
FortiGate_Transparent # config system settings
FortiGate_Transparent (settings) # set opmode transparent //修改FGT的运行模式为透明模式,默认为NAT路由模式。注意切换透明模式防火墙需要防火墙没有相关接口、策略、路由等配置。
FortiGate_Transparent (settings) # set manageip 192.168.1.100 255.255.255.0 //配置可以管理防火墙的本地IP和网关,以便HTTP/SSH管理防火墙及防火墙的服务更新。
FortiGate_Transparent (settings) # set gateway 192.168.1.99
FortiGate_Transparent (settings) # end
Changing to TP mode
MGMT1或MGMT2口默认有管理权限,以要通过port2 接口管理设备为例,开启port2管理FGT的命令如下:
FortiGate_Transparent # config system interface
FortiGate_Transparent (interface) # edit port2
FortiGate_Transparent (port1) # set allowaccess https http ping ssh //允许网管协议从Port2接口通过https/http/SSH/Ping访问透明模式的FortiGate
FortiGate_Transparent (port1) # end配置步骤
在 FortiGate 上创建 VLAN 子接口,VLAN111 和 VLAN222,分别绑定在 port1 和 port2 下。
重要
建议在不需要的情况下关闭接口配置下的“设备探测”(Device detection)功能,该功能用于 MAC 地址厂商设备信息识别及 MAC 地址过滤,会消耗较多的设备资源。



页面右上角打开 Web CLI,将 VLAN111、VLAN222、port2 三个接口划入到同一个 Forward-Domain 里。这样就将 VLAN111 和 VLAN222 之间的广播域打通了,VLAN111 去访问 VLAN222,则 VLAN TAG 111 就会被替换成 VLAN TAG222,反过来也一样的效果。同时 VLAN111 和 VLAN222 和 Port2 也是一个广播域,这样 VLAN111 和 VLAN222 配置策略后,可以通过 Port2 上互联网。
切换到命令行,将三个接口划入到同一个Forward-Domain里: config system interface edit "VLAN111" set forward-domain 111222 set alias "VLAN111" set interface "port1" set vlanid 111 next edit "VLAN222" set forward-domain 111222 set alias "VLAN222" set interface "port1" set vlanid 222 next edit "port2" set allowaccess ping https ssh http set forward-domain 111222 set alias "TO_Internet" next end这样流量是通过防火墙策略控制的,因此接下来需要配置防火墙策略,实现:PC1 和访问 PC2,但是 PC2 不能访问 PC1,同时要求 PC1 和 PC2 都可以正常的访问互联网。




结果验证
PC1 访问 PC2 和 Internet,访问成功。

抓包查看 PC1 访问 PC2。
FortiGate_Transparent # dia sni pac any "host 192.168.1.222 and icmp" 4 interfaces=[any] filters=[host 192.168.1.222 and icmp] 0.765120 VLAN111 in 192.168.1.111 -> 192.168.1.222: icmp: echo request 0.765133 VLAN222 out 192.168.1.111 -> 192.168.1.222: icmp: echo request 0.765136 port1 out 192.168.1.111 -> 192.168.1.222: icmp: echo request 0.769002 VLAN222 in 192.168.1.222 -> 192.168.1.111: icmp: echo reply 0.769012 VLAN111 out 192.168.1.222 -> 192.168.1.111: icmp: echo reply 0.769014 port1 out 192.168.1.222 -> 192.168.1.111: icmp: echo reply在 FortiGate 上镜像 port1 的报文。分析一个 PC1 ping PC2 的过程 VLAN TAG 的变化,非常直接的可以看到请求报文的 VLAN - TAG 从 111 变成了 222,回复报文的 VLAN - TAG 从 222 变成了 111,实现了 remapping VlanID 的功能。




补充
当然组网可以调整为:防火墙完全单臂部署,PC1 属于 VLAN111、PC2 属于 VLAN222、Internet_R 属于 VLAN333,默认情况下相互隔离。
FGT 配置 remapping VlanID,可以让 Port1 子接口 VLAN111、VLAN222、VLAN333 加入到同一个 Forward-Domain 中,让三者广播域互通,同时 FGT 可以通过策略控制三者的流量。
这种方案可以用来作为内网相同网段主机的安全隔离,针对二层环境下东西向流量进行安全控制。
