Yuri Slobodyanyuk Blog on Information Security 2024年07月23日
Fortigate - doing SNAT and DNAT on the same traffic in traditional and Central NAT modes how-to
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了如何在 Fortigate 防火墙上进行源 IP 地址(SNAT)和目标 IP 地址(DNAT)的转换,分别展示了在常规 NAT 模式和中央 NAT 模式下进行配置和验证的过程。重点介绍了如何创建 VIP 对象、安全规则和中央 NAT 规则,并通过抓包分析了数据包的转换过程。

🎯 **在常规 NAT 模式下进行 SNAT 和 DNAT** 在常规 NAT 模式下,通过配置 VIP 对象将外部 IP 地址转换为内部 IP 地址,并通过安全规则设置 NAT 和源 IP 地址。例如,要将内部服务器的 IP 地址和端口 80 映射到外部 IP 地址和端口 8080,同时将连接到服务器的客户端 IP 地址改为 Fortigate 内部接口的 IP 地址,需要配置 VIP 对象和安全规则,并在安全规则中启用 NAT 并设置源 IP 地址。 验证过程可以通过在 Fortigate 上进行抓包分析,观察数据包的源地址和目标地址是否被成功转换。

🎯 **在中央 NAT 模式下进行 SNAT 和 DNAT** 在中央 NAT 模式下,NAT、安全规则和 VIP 配置在不同的部分进行,相互独立。配置流程包括: 1. 创建 VIP 对象,将外部 IP 地址转换为内部 IP 地址。 2. 创建安全规则,允许访问 VIP 配置中使用的内部 IP 地址。 3. 在中央 NAT 策略中创建规则,设置外部客户端连接到内部主机的源 IP 地址和目标 IP 地址,并指定源 IP 地址的转换目标。 验证过程同样可以通过在 Fortigate 上进行抓包分析,观察数据包的源地址和目标地址是否被成功转换。

🎯 **CLI 配置** 本文还展示了在中央 NAT 模式下进行 SNAT 和 DNAT 的 CLI 配置示例,包括中央 NAT 映射配置、安全策略配置和 VIP 配置。 CLI 配置示例可以帮助用户更好地理解配置过程,并为实际操作提供参考。

When the situation requires to translate both - source and destination addresses in incoming packets , it may be not obvious how to do so. In this article I will show how to do it in either usual NAT or Central NAT modes.

Translate source IP address (SNAT) and Destination IP (DNAT) in usual, non-Central NAT mode

Configuration

This is how it is being done in most of the deployments.

    Configure VIP as usual, translating the destination IP address from external to internal one.

    In security rule using the VIP object, enable NAT and set either outgoing interface or IP Pool as the source IP address.

In the following examples I want to make accessible internal server with IP of 172.20.20.218 and port 80 via external IP of 10.10.10.218 and port 8080. Additionally, I want clients connecting to the server to come from the source of 172.20.20.254 of the Fortigate internal (port2) interface.

Figure 1. VIP translating incoming connections to port 8080 to internal server 172.20.20.218 and port 80


Figure 2. Security rule using the VIP

Verification:

Sniffer on the Fortigate
FGT-7 # diagnose sniffer packet any ' port 8080 or net 172.20.20.0/24' 4Using Original Sniffing Modeinterfaces=[any]filters=[ port 8080 or net 172.20.20.0/24]4.579674 port1 in 172.14.14.1.56352 -> 10.10.10.218.8080: syn 1639243840  (1)4.579752 port2 out 172.20.20.254.56352 -> 172.20.20.218.80: syn 1639243840  (2)

    First packet from client 172.14.14.1 arrives to external interface destined to 10.10.10.218 port 8080

    Packet’s source and destination are translated: source from 172.14.14.1 to 172.20.20.254 (internal port2 IP on the Fortigate) and destination from 10.10.10.218 to 172.20.20.218 (Internal server IP)

Translate Source and Destination IP addresses when the Central NAT is enabled

The functionality does not change with switching to the Central NAT, but NAT, security rules, and VIP configurations are done in separate sections and do not depend on each other.

The workflow is:

    Create VIP object in Policy & Objects → DNAT & Virtual IP as usual.

    Create the security rule allowing access to the TRANSLATED destination IP, i.e. internal IP used in VIP configuration.

    Create the following rule in Policy & Objects → Central NAT policy:

      Direction: External to Internal interface

      Src IP: All or as needed, represents external clients connecting to the internal hosts, used for matching only, not for translating.

      Dst IP: Internal IP address of the internal host, i.e. IP after DNAT translation.

      Translation: Here we set to what IP address we want Source IP of the external client to be translated - pick either outgoing interface or IP Pool.

Configuration

Figure 3. Create VIP object in usual way.


Figure 4. Security rule allowing access to the internal server


Figure 5. Central NAT rule for the purpose of doing SNAT

Verification

Sniffer on Fortigate
FGT-7 # diagnose sniffer packet any ' port 8080 or host 172.20.20.218' 4Using Original Sniffing Modeinterfaces=[any]filters=[ port 8080 or host 172.20.20.218]6.396542 port1 in 172.14.14.1.58630 -> 10.10.10.218.8080: syn 13963313296.396611 port2 out 172.20.20.254.58630 -> 172.20.20.218.80: syn 1396331329

CLI configuration

Full configuration for the Central NAT case:
FGT-7 # show firewall central-snat-mapconfig firewall central-snat-map    edit 1        set uuid 5f691854-bc8f-51eb-bd91-c227379e4792        set srcintf "port1"        set dstintf "port2"        set orig-addr "all"        set dst-addr "Server_172.20.20.218"        set protocol 6    nextendFGT-7 # show firewall policyconfig firewall policy    edit 1        set name "VIP-with-SNAT-and-DNAT-in-CNAT"        set uuid 15ac35d4-bc8f-51eb-ad82-7fc0a73227b3        set srcintf "port1"        set dstintf "port2"        set srcaddr "all"        set dstaddr "Server_172.20.20.218"        set action accept        set schedule "always"        set service "ALL"        set logtraffic all    nextendFGT-7 # show firewall vipconfig firewall vip    edit "VIP-as-usual"        set uuid 5eda6046-bc76-51eb-cbe7-ab34fa9b44ff        set extip 10.10.10.218        set mappedip "172.20.20.218"        set extintf "any"        set portforward enable        set extport 8080        set mappedport 80    nextend

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Fortigate NAT SNAT DNAT 网络安全
相关文章