How a firewall processes a packet: sessions, routing, NAT and policy order across vendors
In short: A stateful firewall checks whether a packet belongs to an existing session; if it does, it is forwarded quickly. For a new session the firewall works out the egress interface and zone from routing and NAT, matches the security policy, then inspects the application and content. Each vendor orders NAT and policy slightly differently, which decides whether rules use original or translated addresses.
Sessions first
A stateful firewall tracks each connection in a session table, keyed by source and destination addresses and ports, protocol and zone. The first packet of a connection takes the full ("slow") path through every check. Once a session is created, later packets in both directions match it and are forwarded on the fast path, with only inspection features still applied. This is why a rule change may not affect existing connections until they are cleared or time out.
The steps for a new session
- Ingress checks: which interface and zone the packet arrived on, basic sanity checks, and protection features such as flood or spoofing protection.
- Destination lookup: the firewall works out where the packet will go, using the routing table and any destination NAT, which gives the egress zone.
- Security policy: the first matching rule for source zone, destination zone, addresses, application, service and user decides allow or deny.
- Inspection: application identification, IPS, antivirus, URL filtering, TLS decryption where configured.
- Egress: source NAT is applied and the packet leaves.
NAT and policy: which addresses go in the rule?
This is the part that differs by vendor and trips people up most.
- Palo Alto Networks: NAT policy is evaluated first to find the egress zone, but the security policy uses pre-NAT addresses and post-NAT zone. For an inbound port forward, the security rule's destination is the public address, and the destination zone is the internal zone.
- FortiGate: firewall policies use the real (mapped) internal address when a virtual IP (VIP) object is used for inbound NAT; you reference the VIP object in the policy.
- Cisco ASA (8.3 and later) and FTD: access rules use real (untranslated) addresses for the inside server, not the public address.
- Cisco IOS routers: inbound ACLs on the outside interface see the public address before NAT, as covered in the NAT troubleshooting note.
When in doubt, use the vendor's packet tracing tool, which shows exactly which NAT and policy rules a test packet matches.
Troubleshooting tools
- Cisco ASA/FTD:
packet-tracer input outside tcp 203.0.113.5 50000 198.51.100.10 443simulates a packet through every phase. - Palo Alto:
test security-policy-matchandtest nat-policy-match, plus session browser and packet diagnostics. - FortiGate:
diagnose debug flowshows each step for live packets. - Session table views show whether a session exists, its NAT and which rule allowed it.
Real-world example: the port forward that "did not work"
An engineer moving from an ASA to a Palo Alto firewall rebuilt a web server port forward, writing the security rule with the server's internal address as destination, as on the ASA. Traffic was denied. The Palo Alto test command showed the rule never matched, because Palo Alto policy expects the pre-NAT public address with the post-NAT zone. Changing the rule's destination to the public address fixed it.
Practice
Why does a new firewall rule sometimes not affect traffic immediately?
On a Palo Alto firewall, which address and zone does a security rule for an inbound port forward use?
Which Cisco ASA command simulates a packet through NAT and access rules?
packet-tracer.Key takeaways
- Stateful firewalls check sessions first; only new sessions take the full path.
- Routing and NAT decide the egress zone before the security policy is matched.
- Vendors differ on whether rules use pre-NAT or real addresses.
- Use packet tracing tools to see exactly which rules match.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.