FortiGate Central DNAT: TCP Port Forwarding

ravell
8 min read

Introduction#

This lab publishes a DMZ server on a different TCP port. The external client connects to 198.51.100.10:8443, and FortiGate forwards the connection to 10.20.20.10:443. The DMZ server sees the original client IP, 203.0.113.10.

Central DNAT uses an enabled virtual IP (VIP) to define the translation. A separate firewall policy permits the client to reach the mapped server and service. Fortinet Central DNAT guide

Lab Environment#

The client uses 203.0.113.1 on the Internet Router as its gateway. The DMZ server uses 10.20.20.1 on FortiGate port5 so its replies return through the firewall.

ComponentLab configuration
External clientWin7-External, 203.0.113.10, address object EXT-HOST
Incoming interfaceport3 at 198.51.100.2/24, zone Z-WAN1, facing ISP-1 at 198.51.100.1
ISP transitISP-1 172.16.1.1/30 and Internet Router 172.16.1.2/30
Published endpoint198.51.100.10:8443, VIP VIP-WAN1-WEB
Outgoing interfaceport5, zone Z-DMZ, address 10.20.20.1/24
DMZ server10.20.20.10/24, address object DMZ-WEB, TCP listener on port 443
Firewall policyWAN1-DMZ-WEB, ID 110
image
image

Figure 1. The inbound test follows WAN1 to the DMZ. FortiGate maps the published TCP port 8443 to port 443 on the server.

On ISP-1, route 203.0.113.0/24 through 172.16.1.2. On the Internet Router, route 198.51.100.0/24 through 172.16.1.1. The second route sends connections to the public VIP toward WAN1.

FortiGate Setup

On the lab FortiGate, configure the interfaces, zones, return route, and address objects below. In the GUI, use Network → Interfaces, Network → Static Routes, and Policy & Objects → Addresses. Enable Central SNAT in System → Settings to use Central NAT mode for this lab. FortiOS Central SNAT settings

Copy code to clipboard
Open code in new window
Disable hover highlighting
1config system interface 2 edit "port3" 3 set mode static 4 set ip 198.51.100.2 255.255.255.0 5 next 6 edit "port5" 7 set mode static 8 set ip 10.20.20.1 255.255.255.0 9 next 10end 11 12config system zone 13 edit "Z-WAN1" 14 set interface "port3" 15 next 16 edit "Z-DMZ" 17 set interface "port5" 18 next 19end 20 21config router static 22 edit 0 23 set dst 203.0.113.0 255.255.255.0 24 set gateway 198.51.100.1 25 set device "port3" 26 next 27end 28 29config firewall address 30 edit "EXT-HOST" 31 set subnet 203.0.113.10 255.255.255.255 32 next 33 edit "DMZ-WEB" 34 set subnet 10.20.20.10 255.255.255.255 35 next 36end 37 38config system settings 39 set central-nat enable 40end

Configure Central DNAT#

The GUI and CLI below show two ways to configure the same VIP and firewall policy.

Virtual IP

VIP in the GUI

Go to Policy & Objects → DNAT & Virtual IPs and create an IPv4 DNAT entry.

SettingValue
NameVIP-WAN1-WEB
StatusEnabled
Interfaceany
Source interface filterport3
TypeStatic NAT
External IP address198.51.100.10
Map to IPv4 address10.20.20.10
Port ForwardingEnabled, TCP, One to one
External service port8443
Map to IPv4 port443

The Interface field is set to any, and the Source interface filter limits the VIP to traffic arriving on port3.

FortiGate Central DNAT VIP with port3 as the source interface filter and TCP port 8443 mapped to port 443
FortiGate Central DNAT VIP with port3 as the source interface filter and TCP port 8443 mapped to port 443

Figure 2. VIP-WAN1-WEB maps the WAN1 endpoint to the DMZ server.

VIP in the CLI

Copy code to clipboard
Open code in new window
Disable hover highlighting
1config firewall vip 2 edit "VIP-WAN1-WEB" 3 set extip 198.51.100.10 4 set mappedip "10.20.20.10" 5 set extintf "any" 6 set srcintf-filter "port3" 7 set portforward enable 8 set protocol tcp 9 set extport 8443 10 set mappedport 443 11 set status enable 12 next 13end

Firewall Policy

Firewall Policy in the GUI

Go to Policy & Objects → Firewall Policy and create a policy named WAN1-DMZ-WEB. Set the destination to the mapped address object DMZ-WEB and select HTTPS for TCP port 443. The client still connects to TCP port 8443 on the VIP.

SettingValue
Incoming and outgoing zonesZ-WAN1 → Z-DMZ
SourceEXT-HOST (203.0.113.10/32)
DestinationDMZ-WEB (10.20.20.10/32)
Schedulealways
ServiceHTTPS (TCP 443)
ActionACCEPT
Log Allowed TrafficAll Sessions
FortiGate firewall policy allowing EXT-HOST in Z-WAN1 to reach DMZ-WEB in Z-DMZ over TCP port 443
FortiGate firewall policy allowing EXT-HOST in Z-WAN1 to reach DMZ-WEB in Z-DMZ over TCP port 443

Figure 3. Firewall policy WAN1-DMZ-WEB allows the translated connection.

Firewall Policy in the CLI

The CLI below creates WAN1-DMZ-WEB with policy ID 110, using the zones and address objects defined above. For a policy created in the GUI, find WAN1-DMZ-WEB in show firewall policy to identify its assigned ID.

Copy code to clipboard
Open code in new window
Disable hover highlighting
1config firewall policy 2 edit 110 3 set name "WAN1-DMZ-WEB" 4 set srcintf "Z-WAN1" 5 set dstintf "Z-DMZ" 6 set srcaddr "EXT-HOST" 7 set dstaddr "DMZ-WEB" 8 set action accept 9 set schedule "always" 10 set service "HTTPS" 11 set logtraffic all 12 set status enable 13 next 14end

Test the Published Port#

Start the iperf3 listener on the DMZ server. The test sends iperf3 traffic over TCP. The HTTPS service object matches the translated port, and the lab uses a plain TCP listener.

sh
Copy code to clipboard
Open code in new window
Disable hover highlighting
1sudo iperf3 -s -p 443

Start the packet capture on the FortiGate before connecting:

Copy code to clipboard
Open code in new window
Disable hover highlighting
1diagnose sniffer packet any '(host 203.0.113.10 or host 10.20.20.10) and tcp' 4 40 l

Run the test from Win7-External:

cmd
Copy code to clipboard
Open code in new window
Disable hover highlighting
1iperf3.exe -c 198.51.100.10 -p 8443 -t 10

The Win7 client completed the test, and the DMZ server reported 3.00 MBytes received. The original run used source port 1033 for the iperf3 control connection and 1034 for the data connection.

Win7 iperf3 output showing a completed test to 198.51.100.10:8443 from local source port 1034
Win7 iperf3 output showing a completed test to 198.51.100.10:8443 from local source port 1034

Figure 4. Win7-External connects to TCP port 8443 and completes the transfer.

Verify the Translation#

The FortiGate sniffer recorded the SYN and SYN-ACK for data connection 1034 on both interfaces. The client IP and source port stayed the same on the way to the DMZ. On the return path, FortiGate restored the VIP address and published port as the reply source.

Capture pointSourceDestination
SYN enters port3203.0.113.10:1034198.51.100.10:8443
SYN leaves port5203.0.113.10:103410.20.20.10:443
SYN-ACK enters port510.20.20.10:443203.0.113.10:1034
SYN-ACK leaves port3198.51.100.10:8443203.0.113.10:1034
image
image

Figure 5. The four capture points show the request destination changing on ingress and the reply leaving WAN1 with the VIP as its source.

Forward Traffic Log

The forward traffic list shows the iperf3 control connection on source port 1033 and the data connection on 1034. Both entries show destination NAT to 10.20.20.10:443 through port5 under policy 110.

FortiGate forward traffic list showing source ports 1033 and 1034, the translated destination 10.20.20.10:443, and policy 110
FortiGate forward traffic list showing source ports 1033 and 1034, the translated destination 10.20.20.10:443, and policy 110

Figure 6. The forward traffic list shows both connections from the iperf3 test.

Open Log Details for source port 1034 to see NAT Translation: Destination, NAT IP: 10.20.20.10, NAT Port: 443, and policy 110. The log records TCP reset from server at session closure. The packet capture shows the handshake, and the iperf3 results confirm that data reached the server before the session ended.

FortiGate traffic log details for source port 1034 showing original port 8443, translated port 443, and policy 110
FortiGate traffic log details for source port 1034 showing original port 8443, translated port 443, and policy 110

Figure 7. The log for the data connection identifies the translated destination and matched policy.

Inspect an Active Session

To see the translation while a test runs, prepare these filters in a second FortiGate console:

Copy code to clipboard
Open code in new window
Disable hover highlighting
1diagnose sys session filter clear 2diagnose sys session filter src 203.0.113.10 3diagnose sys session filter proto 6 4diagnose sys session filter policy 110

While iperf3 is transferring data, run diagnose sys session list. After saving the output, run diagnose sys session filter clear. Fortinet session table guide

A repeat test produced this session entry on source port 1038:

Copy code to clipboard
Open code in new window
Disable hover highlighting
1hook=pre dir=org act=dnat 203.0.113.10:1038->198.51.100.10:8443(10.20.20.10:443) 2hook=post dir=reply act=snat 10.20.20.10:443->203.0.113.10:1038(198.51.100.10:8443)

The first line shows the destination mapping. The reply line uses act=snat because FortiGate rewrites the reply's source from the DMZ server address and port back to the VIP address and port. This is the reverse translation of the original DNAT.

Troubleshooting#

What you seeWhat to check
No SYN arrives on port3Check that the upstream device can deliver traffic for 198.51.100.10 to WAN1.
SYN arrives on port3 and no SYN leaves port5Check VIP status, the port3 filter, and the policy's source, mapped destination, and TCP service.
SYN leaves port5 and no reply returnsCheck the DMZ listener on TCP 443, the server firewall, and the gateway 10.20.20.1.