Lesson 45: Network Address Translation (NAT)
NAT is a fundamental technology that allows multiple devices in a private network (using reserved IP addresses like 192.168.x.x) to share a single, public, routable IP address when accessing the internet.
Why NAT is Necessary
- IP Address Conservation: It preserves public IPv4 addresses by allowing thousands of private devices to use one public IP.
- Security: Private addresses are hidden from external networks, providing a basic layer of security.
How NAT Works (The Router's Role)
NAT typically occurs on the router sitting between the private LAN and the public internet.
Example: A client (192.168.1.10:12345) requests a web page from a public server (203.0.113.10:80). The public address of the router is 1.2.3.4.
- Translation: When the packet leaves the router, the router swaps the private source IP (
192.168.1.10) with its own public IP (1.2.3.4). - Port Mapping (PAT): To keep track of which internal device made the request, the router also changes the source port number (
12345) to a unique public port (50000) and records this mapping in the NAT table. - Return Traffic: When the server replies, the packet arrives at
1.2.3.4:50000. The router looks up50000in its NAT table, finds the original device (192.168.1.10:12345), swaps the IP and port back, and forwards the packet internally.
Key Concept: This technique, often called Port Address Translation (PAT) or NAT Overload, is the reason your entire home can access the internet using one public IP address assigned by your ISP.