L3 · addressing · reviewed

NAT

Network Address Translation

Rewrites the IPv4 addresses — and usually the transport ports — at a realm boundary so many private hosts share fewer public addresses.

Presenter modeEmbed this figure

Overview of traditional NATRFC 3022 · INFORMATIONAL · January 2001Address and Port MappingRFC 4787 · BEST CURRENT PRACTICE · January 2007Requirements for CGNsRFC 6888 · BEST CURRENT PRACTICE · April 2013IntroductionRFC 6146 · PROPOSED STANDARD · April 2011Address Allocation for Private InternetsRFC 1918 · BEST CURRENT PRACTICE · February 1996

Why it exists

IPv4 addresses ran short. Private address space lets many networks reuse the same blocks, but those addresses are not unique on the public internet and cannot be routed there without a boundary that rewrites them. Address Allocation for Private InternetsRFC 1918 · BEST CURRENT PRACTICE · February 1996

Traditional NAT — Basic NAT and NAPT — is that boundary. NAPT is what almost everyone deploys: many internal addresses share one external address, distinguished by transport port. Overview of NAPTRFC 3022 · INFORMATIONAL · January 2001

NAT64 exists for a different shortage story: IPv6-only clients reaching IPv4-only servers. It is a translator between families, not a rename of IPv4 NAPT. IntroductionRFC 6146 · PROPOSED STANDARD · April 2011

One public address, many private sources

NAPT rewrites the source address and transport port on the way out, records the mapping, and reverses it on the way back.

PC sends a packet toward the public server. The source is 192.168.1.10 with an ephemeral TCP port — an address that is not unique on the internet and must not leave as-is. PC · 192.168.1.10: Source 192.168.1.10:50100. NAT · 203.0.113.1. Server · 198.51.100.20.

PC · 192.168.1.10Source: 192.168.1.10:50100NAT · 203.0.113.1Server · 198.51.100.20
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
PC · 192.168.1.10hostSource: 192.168.1.10:50100
NAT · 203.0.113.1router
Server · 198.51.100.20host
PC · 192.168.1.10NAT · 203.0.113.1linkup
NAT · 203.0.113.1Server · 198.51.100.20linkup
1 / 6

PC sends a packet toward the public server. The source is 192.168.1.10 with an ephemeral TCP port — an address that is not unique on the internet and must not leave as-is.

RFC 1918 private addresses are not routed on the public internet. Crossing the boundary without rewriting leaves the reply with nowhere to go.

What changed

  • Emphasis on PC · 192.168.1.10
  • PC · 192.168.1.10: Source → 192.168.1.10:50100
  • Src 192.168.1.10: PC · 192.168.1.10 → NAT · 203.0.113.1

How it works

On outbound traffic the NAT replaces the internal source address — and for NAPT the source transport port — with an external pair, then stores the binding. Return traffic matches the external destination and is rewritten back. Overview of NAPTRFC 3022 · INFORMATIONAL · January 2001

Every rewrite touches checksums. The IPv4 header checksum covers the addresses; TCP and UDP checksums cover a pseudo-header that includes them. Skipping either produces a packet the far end silently drops. IP, TCP, UDP and ICMP Header ManipulationsRFC 3022 · INFORMATIONAL · January 2001

Endpoint-independent mapping keeps one external port for an internal source regardless of destination. RFC 4787 requires it because peer-to-peer and UNSAF techniques depend on learning one public binding and reusing it. Address and Port MappingRFC 4787 · BEST CURRENT PRACTICE · January 2007

Filtering is separate from mapping. Endpoint-independent filtering accepts inbound packets to a mapped port from any external address; address-dependent filtering only accepts peers the internal host has already contacted. Filtering BehaviorRFC 4787 · BEST CURRENT PRACTICE · January 2007

On the wire

Constructed examples, encoded from the field table below them — not captured traffic.

IHL 5, so no options. DF is set because the sender is doing path MTU discovery — which is why a filtered ICMP turns this into a black hole rather than a retry at a smaller size.

Link layer
Ethernet with EtherType 0x0800, or whatever the medium uses to say "IPv4 follows". RFC 791
IPv4 header
Version, length, differentiated services, fragmentation control, TTL, protocol, addresses. RFC 791
Payload
Whatever the protocol field names — 1 for ICMP, 6 for TCP, 17 for UDP, 89 for OSPF, 103 for PIM. RFC 791

Configure it

Many private hosts share one public address via overload (NAPT).

Cisco IOS-XE 17.12 · ISR 4451, Catalyst 8300draft

  1. ip access-list standard NAT-INSIDE
     permit 192.168.1.0 0.0.0.255

    Matches the inside local prefixes that are allowed to create translations. Anything not matched is forwarded without NAT — or dropped, depending on other policy.

  2. ip nat pool PUBLIC 203.0.113.1 203.0.113.1 prefix-length 32

    A one-address pool. Overload (PAT) is what lets many inside hosts share it; without overload this would be one-to-one Basic NAT and would exhaust immediately.

    RFC 3022 §2.2

  3. ip nat inside source list NAT-INSIDE pool PUBLIC overload

    Creates dynamic NAPT mappings from the ACL to the pool, translating transport ports so the single external address can be shared.

    Common mistake: Omitting `overload` on a single-address pool. The first host gets the address; every subsequent translation fails.

    RFC 3022 §2.2

  4. interface GigabitEthernet0/0/0
     ip nat inside

    Marks the interface facing the private realm. Translation decision is directional: inside-to-outside uses this classification.

  5. interface GigabitEthernet0/0/1
     ip nat outside

    Marks the interface facing the public realm. Return traffic is matched against the translation table on this side.

Verify

show ip nat translations
Dynamic bindings of inside local to outside global address and port.
show ip nat statistics
Pool utilisation and miss counts when new mappings cannot be created.

Caveats

  • Marked draft: syntax has not been checked against Cisco documentation or a device.
  • Hairpin / NAT reflection is platform- and version-specific; do not assume this stanza enables it.

When it breaks

Symptom first, because that is what you have when it happens.

  1. Two internal hosts cannot reach each other by the public name of a service that lives inside the same network.

    Narrow it down

    1. Resolve the name from inside and confirm it returns the public address.
    2. Check whether the NAT device translates a packet whose source and destination are both inside.
    3. Compare with resolving the internal address directly, which will work.

    Cause

    The packet leaves the client toward the public address, reaches the NAT device, and would have to be translated and sent straight back out the interface it arrived on. Many devices will not do that.

    Fix

    Enable hairpin NAT, or run split-horizon DNS so the internal name resolves to the internal address and no translation is involved.

    Hairpinning BehaviorRFC 4787 · BEST CURRENT PRACTICE · January 2007
  2. An application works from one network and not another, with no error beyond a timeout.

    Narrow it down

    1. Determine whether the application expects an inbound connection or embeds an address in its payload.
    2. Check the NAT mapping behaviour — whether the external port depends on the destination.
    3. Test from a network with a different NAT type.

    Cause

    Address-dependent mapping. A NAT that allocates a different external port per destination breaks any protocol that learns its own external address from one peer and gives it to another.

    Fix

    Use endpoint-independent mapping, which RFC 4787 requires, or a protocol that does not assume its own address is knowable.

    Address and Port MappingRFC 4787 · BEST CURRENT PRACTICE · January 2007
  3. Under load, new connections fail intermittently while existing ones are fine.

    Narrow it down

    1. Count active translations against the configured pool size.
    2. Check the port range available per external address.
    3. Look at how long translations are held after the last packet.

    Cause

    Port exhaustion. Every translation consumes an external port, and idle timers hold them long after a connection is finished — a browser opening dozens of connections per page multiplies quickly.

    Fix

    Add addresses to the pool, shorten idle timers for the protocols that tolerate it, or move to carrier-grade NAT with per-subscriber port blocks.

    Requirements for CGNsRFC 6888 · BEST CURRENT PRACTICE · April 2013
  4. A protocol that embeds IP addresses in its payload works without NAT and fails through it, while ordinary HTTPS through the same NAT is fine.

    Narrow it down

    1. Identify whether the application carries address or port literals in the payload.
    2. Check whether an ALG is enabled for that protocol on the NAT.
    3. Compare behaviour with the ALG disabled and with a tunnel that avoids translation.

    Cause

    An application-level gateway rewrote payload contents incorrectly, or the application assumed its own address was visible end-to-end. Classic NAT only rewrites headers; payloads are opaque unless an ALG intervenes.

    Fix

    Disable the ALG if the application has its own traversal, or use a protocol that does not embed addresses. Prefer fixing the application over depending on ALG behaviour.

    Application Level GatewaysRFC 4787 · BEST CURRENT PRACTICE · January 2007
  5. An internal service is reachable from some external test points and not others, or never receives unsolicited inbound traffic despite a public address on the NAT.

    Narrow it down

    1. Confirm a static or port-forward mapping exists for that external port.
    2. Check filtering behaviour: address-dependent filtering drops peers the host has not contacted.
    3. Verify the packet arrives on the outside interface with the mapped destination port.

    Cause

    No mapping means no inside destination. Dynamic mappings are created by outbound traffic; inbound services need an explicit static map, and restrictive filtering can still drop peers outside the ones already contacted.

    Fix

    Create an explicit inbound mapping for the service, and prefer endpoint-independent filtering when unsolicited peers must connect.

    Filtering BehaviorRFC 4787 · BEST CURRENT PRACTICE · January 2007

Design notes

Prefer endpoint-independent mapping and test hairpinning before declaring a service “published.” A static inbound map that works from the internet can still fail from inside the same network. Hairpinning BehaviorRFC 4787 · BEST CURRENT PRACTICE · January 2007

Treat ALGs as a last resort. An application-level gateway that rewrites IP literals inside SIP or FTP couples the NAT to application syntax; RFC 4787 recommends avoiding ALGs that interfere with UNSAF traversal. Application Level GatewaysRFC 4787 · BEST CURRENT PRACTICE · January 2007

NAT is not a security policy. Unsolicited inbound traffic fails only because there is no mapping. Anything that creates an outbound mapping — malware included — gets a return path, and the NAT applies no content rule to what comes back.

Under carrier-grade load, port allocation and idle timers dominate failures. RFC 6888 requires per-subscriber port limits and logging that can attribute an external address and port to a subscriber at a time. Requirements for CGNsRFC 6888 · BEST CURRENT PRACTICE · April 2013

Misconceptions

NAT is a firewall.
It blocks unsolicited inbound traffic as a side effect of having nowhere to send it, not as a policy. Anything that establishes an outbound mapping — including malware — gets a return path, and the NAT applies no rule to what comes back through it.
NAT and PAT are different features.
What almost everyone calls NAT is port address translation: many internal addresses behind one external address, distinguished by port. One-to-one NAT without ports exists but is rarely what is deployed. Overview of NAPTRFC 3022 · INFORMATIONAL · January 2001
IPv6 removes the need for NAT, so IPv6 has no NAT.
IPv6 removes the address-shortage reason for it. NAT66 and NPTv6 exist and get deployed for multihoming and address independence, and NAT64 is essential to reaching IPv4-only services from an IPv6-only network. IntroductionRFC 6146 · PROPOSED STANDARD · April 2011

More walkthroughs

Hairpinning: inside talking to inside via the public addressfailure

An internal client resolves a service to its public address. The packet hits the NAT and must be translated and sent back out the interface it arrived on — many devices will not.

The client asks for the service by name. Public DNS returns 203.0.113.1 — the NAT’s outside address that also has a static mapping to the internal server. Client · .20: Resolved 203.0.113.1. Server · .50. NAT · 203.0.113.1. Public DNS. Internet.

Client · .20Resolved: 203.0.113.1Server · .50NAT · 203.0.113.1Public DNSInternet
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
Client · .20hostResolved: 203.0.113.1
Server · .50host
NAT · 203.0.113.1router
Public DNShost
Internetcloud
Client · .20NAT · 203.0.113.1linkup
Server · .50NAT · 203.0.113.1linkup
NAT · 203.0.113.1Public DNSlinkup
NAT · 203.0.113.1Internetlinkup
1 / 5

The client asks for the service by name. Public DNS returns 203.0.113.1 — the NAT’s outside address that also has a static mapping to the internal server.

What changed

  • Emphasis on Public DNS
  • Client · .20: Resolved → 203.0.113.1
  • DNS query: Client · .20 → NAT · 203.0.113.1

NAPT rewrites IPv4; NAT64 translates between familiescomparison

Traditional NAPT stays inside IPv4. Stateful NAT64 exists so an IPv6-only client can reach an IPv4-only server — a different translator with different state.

Traditional NAPT never changes the IP version. An IPv4 packet enters, an IPv4 packet leaves, with source address and port rewritten. The packet anatomy is still the IPv4 header. IPv4 client. NAPT. IPv4 server. IPv6 client. NAT64. IPv4-only server.

IPv4 clientNAPTIPv4 serverIPv6 clientNAT64IPv4-only server
  • Link
  • Blocking
  • Packet in flight
  • Discarded
  • Emphasis
Select a device to read its state. Arrow keys walk the topology.
Text equivalent of this diagram
Devices and links at this step
ElementKindState
IPv4 clienthost
NAPTrouter
IPv4 serverhost
IPv6 clienthost
NAT64router
IPv4-only serverhost
IPv4 clientNAPTlinkup
NAPTIPv4 serverlinkup
IPv6 clientNAT64linkup
NAT64IPv4-only serverlinkup
1 / 5

Traditional NAPT never changes the IP version. An IPv4 packet enters, an IPv4 packet leaves, with source address and port rewritten. The packet anatomy is still the IPv4 header.

What changed

  • Emphasis on NAPT
  • IPv4 → IPv4: IPv4 client → NAPT
  • Rewritten IPv4: NAPT → IPv4 server

Terms

NAPT
Network Address Port Translation: many internal addresses share one external address, distinguished by transport port. What most deployments call “NAT” or “PAT”.
Hairpinning
When two hosts behind the same NAT communicate using each other’s external mapped addresses, the NAT must translate and send the packet back out the inside interface. RFC 4787 requires it.
Endpoint-independent mapping
A NAT mapping behaviour where the external address and port for an internal source do not depend on the destination. Required by RFC 4787 so a host can learn one public binding and reuse it with other peers.

Check yourself

  • An internal client cannot reach an internal server by its public hostname. What is the cleanest fix?
  • What does endpoint-independent mapping mean?
  • Why is NAT not a security control?
  • Under heavy load, why do new connections fail while existing ones continue?
  • On outbound NAPT, which IPv4 header field is rewritten for every packet?
  • Why must a NAT adjust the TCP checksum when it rewrites the IPv4 source address?
  • How does stateful NAT64 differ from traditional IPv4 NAPT?
  • A static port forward exists, but unsolicited peers still cannot connect. What else might be wrong?