NAT loopback, also called hairpin NAT or NAT hairpinning, is a router feature that lets a host on a private network reach another internal host through the router’s public IP address and a forwarded port. In Internet addressing, it closes a gap left by port forwarding: without it, a published service works for outside users but fails for clients sitting on the same local network.
The behavior is specified for NAT devices in RFC 4787 (UDP) and RFC 5382 (TCP), which recommend that a NAT support hairpinning. Many consumer routers implement it, some implement it only partially, and some do not implement it at all, which makes it a frequent cause of confusing connectivity failures in home and small office networks.
Why NAT loopback is needed
NAT loopback is needed because a destination NAT rule created for port forwarding normally applies only to packets arriving on the WAN interface. A request from an internal client to the public address enters through the LAN interface, so the router may never apply the forwarding rule and the connection fails.
The problem appears whenever a domain name resolves to the public IP address of the home or office connection. A laptop on Wi-Fi that opens the company webmail, a game client that connects to a self-hosted server, or a phone that reaches a home camera by its public hostname all depend on the router handling this internal-to-public-to-internal path.
How hairpin NAT rewrites the packets
Hairpin NAT works by applying two translations to the same packet: a destination translation that redirects it to the internal server, and a source translation that replaces the client address with the router’s own address. The traffic makes a U-turn inside the router, which gives the technique its name.
The source translation is the critical step. If the router changed only the destination, the server would see a private client address on its own subnet and reply directly, bypassing the router. The client would then receive a reply from an unexpected address and discard it as unrelated traffic, so the TCP handshake never completes.
The table below traces one web request from a client at 192.168.1.20 to a server at 192.168.1.10, with the public address 203.0.113.5 forwarded on port 443.
| Step | Source address | Destination address |
|---|---|---|
| Client sends request | 192.168.1.20:51000 | 203.0.113.5:443 |
| After destination NAT | 192.168.1.20:51000 | 192.168.1.10:443 |
| After source NAT | 192.168.1.1:40000 | 192.168.1.10:443 |
| Server replies | 192.168.1.10:443 | 192.168.1.1:40000 |
| Router restores mapping | 203.0.113.5:443 | 192.168.1.20:51000 |
A known side effect is that server logs show the router’s address for every internal client, because the original source has been masked. Some routers can skip source translation when the server and client are on different internal subnets, which preserves client addresses while still routing correctly.
NAT loopback compared with related techniques
NAT loopback is one of several ways to make internal clients reach an internally hosted service by its public name. The alternatives differ in where the problem is solved: in the router, in DNS or in the client itself.
| Approach | Where it works | Main advantage | Main drawback |
|---|---|---|---|
| NAT loopback | Router or firewall | No DNS or client changes | Masks client addresses, adds router load |
| Split-horizon DNS | Internal DNS server | Direct LAN path, real client addresses | Requires maintaining two DNS views |
| Hosts file entry | Individual client | Simple for one device | Does not scale, breaks on roaming devices |
| Separate internal hostname | Users and applications | No special infrastructure | Different names inside and outside |
NAT loopback should not be confused with the loopback address 127.0.0.1 or ::1, which refers to the host itself and never leaves the device. It also differs from carrier-grade NAT (CGNAT), where the public address belongs to the provider and hairpinning must be supported by provider equipment rather than the home router.
Configuring and testing NAT loopback
On many consumer routers NAT loopback is enabled automatically whenever a port forwarding rule exists. On business firewalls and open-source router platforms, it is usually an explicit option called NAT reflection, hairpin NAT or loopback, sometimes with a choice between pure NAT and a proxy-based mode.
The decision table below summarizes common situations and the recommended configuration.
| Situation | Recommended choice | Reason |
|---|---|---|
| Home server, consumer router | Enable NAT loopback | Simplest option with no extra services |
| Office with internal DNS server | Use split-horizon DNS | Keeps traffic local and logs accurate |
| Router lacks hairpin support | Split DNS or hosts entries | Router cannot be fixed by settings alone |
| Connection behind CGNAT | Tunnel or provider IPv6 | Public address is not under local control |
To test the feature, compare access from two networks: open the public hostname from a device on mobile data, then from a device on the local Wi-Fi. Success from outside and failure from inside is the classic signature of missing hairpin support.
Limitations and common problems
NAT loopback is a workaround for IPv4 address scarcity, and it inherits the limitations of NAT itself. Typical issues include the following.
- Lost client identity: access control and logging on the server see only the router address.
- Extra router load: all internal traffic to the service crosses the router twice, which can limit throughput on weak hardware.
- Partial implementations: some routers hairpin TCP but not UDP, breaking game servers and VoIP.
- Dynamic public addresses: when the public IP changes, dynamic DNS updates must reach clients before hairpinning works again.
With IPv6 and globally routable addresses, internal hosts can reach a server by its real global address, so hairpinning is generally unnecessary. In dual stack networks, however, clients that fall back to IPv4 still depend on it.
In plain words
Imagine an apartment building with one street address. Visitors ring the front door, and the doorman sends them to the right apartment. Now imagine a resident who wants to visit a neighbor but walks outside and rings the front door instead of using the hallway. Some doormen are confused by this and turn the resident away.
NAT loopback is the doorman who handles that case correctly. It lets a device at home or at the office reach a local server using the same public address that outside visitors use, so one address works from everywhere.
A real-world example
A small architecture office runs a file-sharing server on its local network at 192.168.10.5 and publishes it as files.example-office.net, which resolves to the office’s public IPv4 address. The router forwards TCP port 443 to the server, and staff working from home connect without problems.
Inside the office, however, the same laptops cannot open the address, and the browser times out. The administrator tests from a phone on mobile data, sees that external access works, and concludes that the router lacks hairpin support. After a firmware update, the router offers a NAT reflection option, which the administrator enables for the forwarded port.
Office laptops now reach the server by the same hostname inside and outside, and synchronization clients no longer need two configurations. The server logs show the router address for internal users, so the administrator later adds split-horizon DNS on the office DNS server to keep internal traffic direct and restore accurate client addresses.