Network Address Translation (NAT)
Understand how routers translate IP addresses and ports, including SNAT, DNAT, PAT, and port forwarding.
Network Address Translation (NAT) lets a network device rewrite IP addresses—and sometimes port numbers—as packets pass between networks. It is the reason many devices in a home can share one public IPv4 address. The router keeps a translation table so replies can find their way back to the device that started the connection.
Think of the router as a receptionist for outgoing conversations: it records which inside device called which outside service, then uses that record to deliver the reply. That is useful, but it does not make the router a firewall or encrypt the traffic.
Follow one packet
Imagine a laptop with the private address 192.168.1.25 contacting a web server at 198.51.100.20. These documentation-only addresses make the example safe to copy.
| Moment | Packet source | Packet destination | What happened |
|---|---|---|---|
| Before NAT | 192.168.1.25:51514 |
198.51.100.20:443 |
The laptop sends a request. |
| Leaving the router | 203.0.113.8:62001 |
198.51.100.20:443 |
The router replaces the private source address and port, then records the mapping. |
| Reply reaches router | 198.51.100.20:443 |
203.0.113.8:62001 |
The server replies to the public mapping. |
| Reply reaches laptop | 198.51.100.20:443 |
192.168.1.25:51514 |
The router looks up its table and restores the original destination. |
The router must remember enough of the connection to match a reply to the right device. If its mapping expires, a late reply may no longer be delivered. The exact mapping rules depend on the protocol and device.
The main kinds
- SNAT (Source NAT) changes the source address. Home-router internet access commonly uses it for outgoing traffic.
- DNAT (Destination NAT) changes the destination address. A port-forwarding rule is a common way to send selected incoming traffic to an inside server.
- PAT/NAPT lets multiple inside connections share one public IPv4 address by assigning distinct translated port numbers. This is the common many-to-one arrangement in home routers.
- Static NAT keeps a fixed one-to-one mapping. Dynamic NAT chooses a mapping from a configured address pool.
These terms describe address translation behavior, not a promise that a connection is allowed. A firewall or other access-control policy should decide which traffic is permitted.
Port forwarding: the reverse doorway
Suppose a private web server listens on 192.168.1.50:443. A port-forwarding rule can tell the edge router to translate an arriving connection for a chosen public port to that private address and port. The rule deliberately makes a service reachable from outside, so only configure it when you understand the exposure and have secured the service.
Port forwarding does not work if the router itself has no reachable public address—for example, when another upstream router or carrier-grade NAT is in the way. That situation is often called double NAT or carrier-grade NAT, depending on where the second translation happens.
NAT is not a security boundary by itself
NAT changes packet addressing; it is not encryption, identity verification, or a complete firewall policy. A home router may combine NAT with stateful filtering, but those are separate functions. Do not treat “behind NAT” as proof that a machine is safe, and do not expose an unpatched service merely because a port-forward rule appears small.
NAT can also make direct peer-to-peer connections harder because a device behind a router may not have a stable, reachable public endpoint. Applications sometimes use coordination or relay techniques to work around that constraint.
NAT in a VM lab
In a VM’s NAT network mode, the virtualization platform usually lets the guest initiate outbound connections through the host or a virtual router. Other machines on the local network typically cannot initiate a connection to the guest unless you configure a forwarding rule. Bridged mode is different: the guest joins the local network as a separate machine.
For a first lab, keep the VM on NAT, confirm it receives an address and default route, and test that it can reach a known service. Change to bridged mode only when the exercise needs the guest to be visible on the LAN.
A calm troubleshooting checklist
- Check the guest’s IP address, subnet mask, and default gateway.
- Confirm the guest can reach its gateway before testing an internet hostname.
- If an IP connection works but a hostname does not, investigate DNS separately; NAT does not resolve names.
- For an inbound service, verify the server is listening, the firewall permits it, and each required forwarding rule targets the correct guest address and port.
- Check whether another router or carrier-grade NAT sits upstream, and inspect router logs or translation-table status when available.
Sources
- RFC 3022: Traditional IP Network Address Translator describes traditional NAT behavior.
- RFC 1918: Address Allocation for Private Internets defines the familiar private IPv4 address ranges.
- RFC 5737: IPv4 Address Blocks Reserved for Documentation reserves the example addresses used in this lesson.