What is NAT, and why is it used?
MediumConceptARP, DHCP & NAT
Answer
NAT (Network Address Translation) is performed by a router that rewrites IP addresses, and usually port numbers, in packets passing between a private network and the internet. It lets many devices with private addresses share one public IPv4 address, which has greatly slowed the exhaustion of IPv4 addresses.
- The common form is PAT (Port Address Translation, or NAT overload): each internal IP and port pair is mapped to a unique port on the public address and recorded in a translation table, so replies can be returned to the right device.
- Unsolicited inbound connections have no table entry and are dropped, which hides internal hosts. Running a server behind NAT needs port forwarding, a fixed rule that sends one public port to an internal host.
- NAT breaks true end-to-end addressing, which complicates peer-to-peer applications such as video calls; they work around it with techniques such as STUN and TURN.
Example: Two home devices reach the same website through a router whose public address is 203.0.113.5:
Inside (private) Outside (public) Destination
192.168.1.7:50001 -> 203.0.113.5:40001 -> 198.51.100.20:443
192.168.1.8:50001 -> 203.0.113.5:40002 -> 198.51.100.20:443
A reply arriving at port 40002 is forwarded to 192.168.1.8:50001.
More in ARP, DHCP & NAT
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | How does DHCP assign an IP address to a device? Explain DORA. | Concept | Medium | Read the answer to How does DHCP assign an IP address to a device? Explain DORA. | |||
| 2 | How does ARP find the MAC address for an IP address? | Concept | Medium | Read the answer to How does ARP find the MAC address for an IP address? | |||
| 3 | What is NAT, and why is it used? | Concept | Medium | Read the answer to What is NAT, and why is it used? | |||
| 4 | What is ICMP, and how do ping and traceroute work? | Concept | Medium | Read the answer to What is ICMP, and how do ping and traceroute work? |