Forward-Domain
Forward-Domain
重要
有 VLAN 的场景建议配置。
网络需求
内部网络有两个 vlan(trunk 环境),网关在路由器上,防火墙工作在透明模式,部署在核心交换与核心路由之间,允许两个 vlan 访问外网,同时两个 vlan 之间需要互访,并且对这两个 vlan 进行保护,开启反病毒过滤。
网络拓扑
拓扑 1:单 VLAN 透传

拓扑 2:多 VLAN 透传,VLAN 之间互访

配置要点
拓扑 1:单 VLAN 透传
- SW 交换机/Internet_R 路由器的基础配置
- 将防火墙配置为透明模式并开启网管
- 配置 LAN 和 WAN 接口的 VLAN 子接口并加入到 forward-domain
- 配置安全策略允许内网 PC(VLAN10 内主机)访问互联网
拓扑 2:多 VLAN 透传,以及 VLAN 之间互访
- SW 交换机/Internet_R 路由器的基础配置
- 新增 Inside 和 Outside 关于 VLAN20 的子接口并加入到 Forward-domain
- 配置 Inside_VLAN20 到 Outside_VLAN20 的安全策略允许内网 PC(VLAN20 内主机)访问互联网
- 配置 VLAN10 与 VLAN20 之间互访的策略
配置步骤
拓扑 1:单 VLAN 透传
SW 交换机/Internet_R 路由器的基础配置(以思科为例)。
SW:
SW: interface Ethernet0/0 switchport trunk allowed vlan 1,10 switchport trunk encapsulation dot1q switchport mode trunk ! interface Ethernet0/1 switchport access vlan 10 switchport mode access !Router:
Router: hostname Internet_R ! interface Ethernet0/0 ip address 192.168.1.99 255.255.255.0 no shutdown ip nat inside ! interface Ethernet0/0.10 encapsulation dot1Q 10 ip address 192.168.10.99 255.255.255.0 no shutdown ip nat inside ! interface Ethernet0/1 ip address 202.100.1.179 255.255.255.0 no shutdown ip nat outside ! 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 overload将防火墙配置为透明模式并开启网管(参考 网络管理 → 透明模式 → 传统透明模式 → 开启透明模式防火墙并保护上网流量)。
新建 LAN 和 WAN 接口的 VLAN10 子接口并加入到 forward-domain。




config system interface edit "Inside_VLAN10" set vdom "root" set alias "LAN_Inside_VLAN10" set interface "port1" set vlanid 10 next edit "Outside_VLAN10" set vdom "root" set alias "WAN_Outside_VLAN10" set interface "port2" set vlanid 10 next end重要
建议在不需要的情况下关闭接口配置下的“设备探测”(Device detection)功能,该功能用于 MAC 地址厂商设备信息识别及 MAC 地址过滤,会消耗较多的设备资源。
为 Inside_VLAN10 和 Outside_VLAN10 接口配置 forward-domain。
FortiGate_Transparent # config system interface FortiGate_Transparent (interface) # edit Inside_VLAN10 FortiGate_Transparent (Inside_VLAN10) # set forward-domain 10 FortiGate_Transparent (Inside_VLAN10) # next FortiGate_Transparent (interface) # edit Outside_VLAN10 FortiGate_Transparent (Outside_VLAN10) # set forward-domain 10 FortiGate_Transparent (Outside_VLAN10) # end重要
Forward-Domain 说明:
默认所有的接口都属于 Forward-Domain 0,可以理解为同一个广播域,在 FortiGate 的概念中,Forward-Domain 才代表真正的广播域,并非 VLAN,而一般的理解交换机的常识都是 VLAN 隔离广播域,因此如果需要使用 VLAN 则务必将 VLAN - ID 和 Fortiward-Domain ID 关联起来,这样就可以以正常的交换机 VLAN 隔离广播域的思维去考虑 FortiGate 的透明模式。Forward-Domain 是一个 FGT 透明模式下比较特别的东西,记住:只要有 VLAN - ID 的场景就需要配置对应的 Forward-Domain ID 这样就不会出现什么问题。
配置防火墙策略允许内网 PC(VLAN10 内主机)访问互联网,注意这里要选择 VLAN 接口。


拓扑 2:多 VLAN 透传,VLAN 之间互访
SW 交换机/Internet_R 路由器的基础配置(以思科为例)。
SW:
interface Ethernet0/0 switchport trunk allowed vlan 1,10,20 switchport trunk encapsulation dot1q switchport mode trunk ! interface Ethernet0/1 switchport access vlan 10 switchport mode access ! interface Ethernet0/2 switchport access vlan 20 switchport mode access !Router:
hostname Internet_R ! interface Ethernet0/0 ip address 192.168.1.99 255.255.255.0 no shutdown ip nat inside ! interface Ethernet0/0.10 encapsulation dot1Q 10 ip address 192.168.10.99 255.255.255.0 no shutdown ip nat inside ! interface Ethernet0/0.20 encapsulation dot1Q 20 ip address 192.168.20.99 255.255.255.0 no shutdown ip nat inside ! interface Ethernet0/1 ip address 202.100.1.179 255.255.255.0 no shutdown ip nat outside ! 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 overload新增 Inside 和 Outside 关于 VLAN20 的子接口并加入到 Forward-domain。



config system interface edit "Inside_VLAN20" set vdom "root" set alias "LAN_Inside_VLAN20" set interface "port1" set vlanid 20 next edit "Outside_VLAN20" set vdom "root" set alias "WAN_Outside_VLAN20" set interface "port2" set vlanid 20 next end为 Inside_VLAN20 和 Outside_VLAN20 接口配置 forward-domain。
FortiGate_Transparent # config system interface FortiGate_Transparent (interface) # edit Inside_VLAN20 FortiGate_Transparent (Inside_VLAN20) # set forward-domain 20 FortiGate_Transparent (Inside_VLAN20) # next FortiGate_Transparent (interface) # edit Outside_Vlan20 FortiGate_Transparent (Outside_VLAN20) # set forward-domain 20 FortiGate_Transparent (Outside_VLAN20) # end配置 Inside_VLAN20 到 Outside_VLAN20 的上网安全策略,允许 VLAN20 内的主机访问 Internet。


此时 VLAN 10 下的 PC 已经可以和 VLAN 20 下的 PC 互访,不需要配置其他策略。
重要
不同 Forward-Domain 下的 VLAN 接口是不能配置在同一条安全策略的源目接口中的。在 VLAN 10 下的 PC 访问 VLAN 20 下的 PC(192.168.10.10 → 192.168.20.10)时,流量会经过 2 次 FortiGate:
- 流量先从 Inside_VLAN10 送到 Outside_VLAN10(匹配 VLAN 10 的上网策略)。此时 FortiGate 创建 192.168.10.10 → 192.168.20.10(Inside_VLAN10 → Outside_VLAN10)的会话。
- 同时,FortiGate 会自动创建 192.168.10.10 → 192.168.20.10(Outside_VLAN20 → Inside_VLAN20)的辅助会话(上述创建会话的 Reflect 会话),流量第二次经过 FortiGate 时,从 Outside_VLAN20 进入并送到 Inside_VLAN20,匹配辅助会话送到 VLAN 20 下的 PC。
结果验证
拓扑 1:单 VLAN10 透传
VLAN10 内的 PC 通过透明模式的 FortiGate 访问互联网。

拓扑 2:多 VLAN 透传,VLAN 之间互访
VLAN20 内的 PC 访问互联网。

VLAN10 内的 PC 访问 VLAN20 的 PC。

查看对应 sniffer 抓包,VLAN 10 主机访问 VLAN 20 主机的 Ping Request 从 Inside_VLAN10 进,从 Outside_VLAN10 出,随后从 Outside_Vlan20 进,从 Inside_VLAN20 出。
FortiGate_Transparent # diagnose sniffer packet any "host 192.168.20.10 and icmp" 4 Using Original Sniffing Mode interfaces=[any] filters=[host 192.168.20.10 and icmp] 3.530807 Inside_VLAN10 in 192.168.10.10 -> 192.168.20.10: icmp: echo request 3.530823 Outside_VLAN10 out 192.168.10.10 -> 192.168.20.10: icmp: echo request 3.530826 port2 out 192.168.10.10 -> 192.168.20.10: icmp: echo request 3.531120 Outside_Vlan20 in 192.168.10.10 -> 192.168.20.10: icmp: echo request 3.531129 Inside_VLAN20 out 192.168.10.10 -> 192.168.20.10: icmp: echo request 3.531130 port1 out 192.168.10.10 -> 192.168.20.10: icmp: echo request 3.531696 Inside_VLAN20 in 192.168.20.10 -> 192.168.10.10: icmp: echo reply 3.531703 Outside_Vlan20 out 192.168.20.10 -> 192.168.10.10: icmp: echo reply 3.531703 port2 out 192.168.20.10 -> 192.168.10.10: icmp: echo reply 3.531856 Outside_VLAN10 in 192.168.20.10 -> 192.168.10.10: icmp: echo reply 3.531859 Inside_VLAN10 out 192.168.20.10 -> 192.168.10.10: icmp: echo reply 3.531859 port1 out 192.168.20.10 -> 192.168.10.10: icmp: echo reply查看 Request 方向与 Reply 方向对应的 debug flow。
Ping Request 第 1 次从 Inside_VLAN10 送到 Outside_VLAN10(匹配 VLAN 10 的上网策略)。此时 FortiGate 创建 192.168.10.10 → 192.168.20.10(Inside_VLAN10 → Outside_VLAN10)的会话。
Request方向第1次过FortiGate: id=65308 trace_id=10 func=print_pkt_detail line=5857 msg="vd-root:0 received a packet(proto=1, 192.168.10.10:2->192.168.20.10:2048) tun_id=0.0.0.0 from Inside_VLAN10. type=8, code=0, id=2, seq=2879." id=65308 trace_id=10 func=init_ip_session_common line=6043 msg="allocate a new session-00000386, tun_id=0.0.0.0" id=65308 trace_id=10 func=br_fw_forward_handler line=578 msg="Allowed by Policy-1:" id=65308 trace_id=10 func=__if_queue_push_xmit line=392 msg="send out via dev-Outside_VLAN10, dst-mac-aa:bb:cc:00:30:00"同时,FortiGate 会自动创建 192.168.10.10 → 192.168.20.10(Outside_VLAN20 → Inside_VLAN20)的辅助会话(上述创建会话的 Reflect 会话),流量第二次经过 FortiGate 时,从 Outside_VLAN20 进入并送到 Inside_VLAN20,匹配辅助会话送到 VLAN 20 下的 PC。
Request方向第2次过FortiGate: id=65308 trace_id=11 func=print_pkt_detail line=5857 msg="vd-root:0 received a packet(proto=1, 192.168.10.10:2->192.168.20.10:2048) tun_id=0.0.0.0 from Outside_VLAN20. type=8, code=0, id=2, seq=2879." id=65308 trace_id=11 func=resolve_ip_tuple_fast line=5945 msg="Find an existing session, id-00000386, original direction" id=65308 trace_id=11 func=br_fw_forward_dirty_handler line=282 msg="auxiliary ses proto=1 dev=19->18 192.168.10.10/2=>192.168.20.10/8" id=65308 trace_id=11 func=npu_handle_session44 line=1322 msg="Trying to offloading session from Outside_VLAN20 to Inside_VLAN20, skb.npu_flag=00000400 ses.state=00008200 ses.npu_state=0x00000100" id=65308 trace_id=11 func=__if_queue_push_xmit line=392 msg="send out via dev-Inside_VLAN20, dst-mac-00:0c:29:39:f3:ac"Reply 方向的流量匹配辅助会话和主会话返回。
Reply方向: id=65308 trace_id=12 func=print_pkt_detail line=5857 msg="vd-root:0 received a packet(proto=1, 192.168.20.10:2->192.168.10.10:0) tun_id=0.0.0.0 from Inside_VLAN20. type=0, code=0, id=2, seq=2879." id=65308 trace_id=12 func=resolve_ip_tuple_fast line=5945 msg="Find an existing session, id-00000386, reply direction" id=65308 trace_id=12 func=br_fw_forward_dirty_handler line=282 msg="auxiliary ses proto=1 dev=19->18 192.168.10.10/2=>192.168.20.10/8" id=65308 trace_id=12 func=npu_handle_session44 line=1322 msg="Trying to offloading session from Inside_VLAN20 to Outside_VLAN20, skb.npu_flag=00000000 ses.state=00008200 ses.npu_state=0x00000100" id=65308 trace_id=12 func=__if_queue_push_xmit line=392 msg="send out via dev-Outside_VLAN20, dst-mac-aa:bb:cc:00:30:00" id=65308 trace_id=13 func=print_pkt_detail line=5857 msg="vd-root:0 received a packet(proto=1, 192.168.20.10:2->192.168.10.10:0) tun_id=0.0.0.0 from Outside_VLAN10. type=0, code=0, id=2, seq=2879." id=65308 trace_id=13 func=resolve_ip_tuple_fast line=5945 msg="Find an existing session, id-00000386, reply direction" id=65308 trace_id=13 func=__if_queue_push_xmit line=392 msg="send out via dev-Inside_VLAN10, dst-mac-00:0c:29:ae:55:70"
查看对应会话,可以看到主会话为 192.168.10.10 → 192.168.20.10(Inside_VLAN10 → Outside_VLAN10),辅助会话有 reflect 标记,Outside_VLAN20 → Inside_VLAN20。
session info: proto=1 proto_state=00 duration=38 expire=21 timeout=0 flags=00000000 socktype=0 sockport=0 av_idx=0 use=4 origin-shaper= reply-shaper= per_ip_shaper= class_id=0 ha_id=0 policy_dir=0 tunnel=/ vlan_cos=0/0 state=may_dirty br statistic(bytes/packets/allow_err): org=120/2/1 reply=120/2/1 tuples=2 tx speed(Bps/kbps): 3/0 rx speed(Bps/kbps): 3/0 orgin->sink: org pre->post, reply pre->post dev=16->17/17->16 gwy=0.0.0.0/0.0.0.0 hook=pre dir=org act=noop 192.168.10.10:2->192.168.20.10:8(0.0.0.0:0) hook=post dir=reply act=noop 192.168.20.10:2->192.168.10.10:0(0.0.0.0:0) misc=0 policy_id=1 pol_uuid_idx=15744 auth_info=0 chk_client_info=0 vd=0 serial=00000386 tos=ff/ff app_list=0 app=0 url_cat=0 rpdb_link_id=00000000 ngfwid=n/a npu_state=0x000100 no_ofld_reason: npu-flag-off reflect info 0: dev=19->18/18->19 npu_state=0x000100 npu info: flag=0x00/0x00, offload=0/0, ips_offload=0/0, epid=0/0, ipid=0/0, vlan=0x0000/0x0000 vlifid=0/0, vtag_in=0x0000/0x0000 in_npu=0/0, out_npu=0/0, fwd_en=0/0, qid=0/0 total reflect session num: 1 total session 1查看当前接口列表,可以看到 4 个 VLAN 接口的 index,与会话中的 dev 对应。
FortiGate # diagnose netlink interface list | grep VLAN if=Inside_VLAN10 family=00 type=1 index=16 mtu=1500 link=0 master=0 if=Outside_VLAN10 family=00 type=1 index=17 mtu=1500 link=0 master=0 if=Inside_VLAN20 family=00 type=1 index=18 mtu=1500 link=0 master=0 if=Outside_VLAN20 family=00 type=1 index=19 mtu=1500 link=0 master=0使用 VLAN20 下的 PC 访问 VLAN 10 下的 PC,也可以正常访问。
