Octet

What is the NAT order of operations on a Cisco IOS router, and why does it matter?

Show the answer

Say this first

It depends on the direction. Inside to outside, IOS routes first and then translates. Outside to inside, it translates first and then routes. In both directions the inbound ACL runs before NAT, and crypto maps and outbound ACLs run after it. So an ACL inbound on the outside interface must match the global address, the router needs a route to the inside local address for incoming traffic, and VPN traffic must be exempted from NAT or it stops matching the crypto ACL.

Go deeper

The sequence, trimmed to what matters

StepInside to outsideOutside to inside
1IPsec decryption, if anyIPsec decryption, if any
2Input ACLInput ACL
3Policy routingNAT, global to local
4RoutingPolicy routing
5NAT, local to globalRouting
6Crypto map checkCrypto map check
7Output ACLOutput ACL

What follows from it

  1. Inbound ACL on the outside interface sees pre-NAT addresses. To let the internet reach SRV1 (192.168.20.10, published as 203.0.113.5), permit host 203.0.113.5, not the private address.
  2. Outbound ACL on the outside interface sees post-NAT addresses, so the sources are inside global.
  3. Inbound ACL on an inside interface sees inside local addresses.
  4. Outside to inside, routing uses the translated destination. R1 needs a route to 192.168.20.10.
  5. Crypto runs after NAT. Traffic to a VPN peer's private network gets PATed first, then no longer matches the private-to-private crypto ACL. Exempt it in the NAT rule:
Cisco IOS
ip access-list extended NAT-USERS
 deny   ip 192.168.10.0 0.0.0.255 10.200.0.0 0.0.255.255
 permit ip 192.168.10.0 0.0.0.255 any
!
ip nat inside source list NAT-USERS interface GigabitEthernet0/0/0 overload
  1. Translation happens only when a packet crosses between an ip nat inside and an ip nat outside interface. Inside to inside is never translated.

Other platforms do it differently

  • Cisco ASA (8.3 and later) matches ACLs against the real, untranslated address: the opposite habit.
  • Linux netfilter does DNAT in PREROUTING, before the routing decision, and SNAT in POSTROUTING, after it. Filter rules in FORWARD see the private destination of a port forward.

Traps

  • Saying NAT happens before routing in both directions.
  • Writing the outside interface ACL with private addresses.
How did you do?Book 3.3 Internet (IP)