Free tech learning for everyone, from basics to pro

Network SecurityNetworking SecurityAdvanced

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.

A typical first-packet path through a stateful firewallIngressinterface,zoneSessionlookupexisting?fast pathRoute / NATlookupegress zone,destinationSecuritypolicyallow ordenyInspectionApp-ID, IPS,URLEgressapply NAT,send
Figure 1. Only the first packet of a session goes through every step; later packets match the session and take the fast path.

The steps for a new session

  1. Ingress checks: which interface and zone the packet arrived on, basic sanity checks, and protection features such as flood or spoofing protection.
  2. Destination lookup: the firewall works out where the packet will go, using the routing table and any destination NAT, which gives the egress zone.
  3. Security policy: the first matching rule for source zone, destination zone, addresses, application, service and user decides allow or deny.
  4. Inspection: application identification, IPS, antivirus, URL filtering, TLS decryption where configured.
  5. 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 443 simulates a packet through every phase.
  • Palo Alto: test security-policy-match and test nat-policy-match, plus session browser and packet diagnostics.
  • FortiGate: diagnose debug flow shows 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?
Existing sessions take the fast path and are not re-evaluated until they are cleared or time out.
On a Palo Alto firewall, which address and zone does a security rule for an inbound port forward use?
The pre-NAT (public) destination address and the post-NAT (internal) destination zone.
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.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
Mohamed Fayas
Role
Founder of FM TecHub
Credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

He writes practical, plain-English guides on networking, security and cloud.

More about the author →

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.

Email updates: coming soon

New notes, tools and security news from FM TecHub by email, explained simply. Free. We're not collecting email addresses yet; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesopening soon

Meanwhile, stay connected: