Curriculum / Network firewall
Firewall rules and NAT
Write zone-to-zone firewall rules, order them correctly, and translate addresses with SNAT and DNAT.
Goal
Write the classic three-zone ruleset (lan → wan allowed, dmz published inward via DNAT, everything else denied) and understand rule evaluation order.
Firewall rules
Rules are evaluated top down, first match wins. Each rule has:
- Source zone / destination zone
- Match — source and destination addresses, protocol, ports
- Action — allow or deny
A minimal secure baseline:
- Allow
lan→wan(any port, or restrict to 80/443/53 for tighter posture) - Allow
wan→dmzonly on the published service ports - Deny everything else (the implicit default)
NAT
Two translations cover most deployments:
- SNAT (source NAT / masquerade) — rewrites private
lansource addresses to the WAN address so replies can return. Applied on egress towan. - DNAT (destination NAT / port forward) — rewrites the WAN address and port to an internal server, publishing a
dmzservice to the internet.
DNAT happens before firewall evaluation, so your wan → dmz rule must match the translated (internal) destination.
Steps
- Open Network → Firewall and add the allow rules in order.
- Open Network → NAT and add SNAT for
lanegress and DNAT for each published service. - Publish and watch apply status.
Verify
- A
lanclient can browse the internet (SNAT works). - The published
dmzservice answers on the WAN address (DNAT works). - A connection attempt from
wantolanis dropped.
Pitfalls
- Rule order matters: a broad deny placed above your allows silently kills everything below it.
- When DNAT "doesn't work", check the firewall rule first — it must allow traffic to the internal address, not the public one.