Destination NAT
Forward a public port to a server
Lesson 13 of 20 · 12 min · Module 4: Address translation
Customers know one public address. The web server lives on a private one. Destination NAT connects the two, one port at a time.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- Read a destination NAT line
- Publish one port of one server
- Pair the translation with a policy rule
The idea
Destination NAT (port forwarding) rewrites the destination of an incoming packet from the firewall's public address to a server's private address. Publishing a service takes two lines that work together: the translation, and a policy rule that allows the translated traffic.
dnat tcp from untrust to public port 25 use mail port 25
allow tcp from untrust to mail port 25
01Read the translation
"dnat tcp from untrust to public port 443 use web port 443" says: a tcp packet from the internet to the public address, port 443, is sent on to the server web, port 443. The source address is not changed, so the server sees the real customer address.
02Add the permission
The translation alone delivers nothing: the default deny still applies. The matching policy rule allows tcp from untrust to web port 443. Only the forwarded port is published; SSH to the public address is neither translated nor allowed.
03Port forwarding on real devices
Every platform has an object or statement for the mapping, and a policy that refers to it.
# nftables
nft add rule ip nat prerouting iifname "wan0" tcp dport 443 dnat to 10.0.2.10:443
# FortiGate: a virtual IP, used as the destination of a policy
config firewall vip
edit "WEB_VIP"
set extip 203.0.113.10
set mappedip "10.0.2.10"
set extintf "wan1"
set portforward enable
set extport 443
set mappedport 443
next
end
# Huawei USG
nat server web_https protocol tcp global 203.0.113.10 443 inside 10.0.2.10 443
Your turn
untrust to public port 443 so it reaches web port 443, and allow the translated traffic with a policy rule. Publish nothing else.What the checks look for
- Customers reach the web server through the public address
- The customer's own address is kept as the source
- Only port 443 is forwarded
- No other server is published
Take this with you
Publishing a service is a pair: a destination NAT line for one port, and a policy rule that allows exactly that traffic.
Go a little further
Publish the same server on the public port 8443 instead, still reaching port 443 on the server, and note which of your two lines had to change.