Sub topic 11
PAT and the NAT Translation Table
Assume you know IPv4 addresses, transport-layer ports, and the difference between a private and a public address. A router performs PAT (Port Address Translation) when many private hosts share one public IPv4 address. PAT is also called NAT overload.
Why PAT is needed
A private host cannot normally use its private source address directly on the public Internet. The NAT router changes the packet's source address to its public address. If several hosts use the same public address, the router also changes their source ports so that each connection remains distinct.
For example:
- Host A sends
192.168.1.10:49152to a web server. - The router changes the source to
203.0.113.5:40001. - Host B sends
192.168.1.11:49152to another server. - The router changes the source to
203.0.113.5:40002.
The private source ports may be equal because the translated public ports are different.
The NAT translation table
The router records each active mapping. A simplified table may look like this:
| Inside local | Inside global | Destination | Protocol |
|---|---|---|---|
| 192.168.1.10:49152 | 203.0.113.5:40001 | 198.51.100.20:443 | TCP |
| 192.168.1.11:49152 | 203.0.113.5:40002 | 198.51.100.30:443 | TCP |
Inside local is the private address and port. Inside global is the public address and translated port. The destination fields help the router associate return traffic with the correct connection. Implementations may use different mapping and filtering rules, so this table is a conceptual model.
When a reply arrives at 203.0.113.5:40001, the router looks up port 40001, changes the destination to 192.168.1.10:49152, and forwards the packet internally. It also updates checksums because IP addresses and ports changed.
A small PAT model
translations = {
("203.0.113.5", 40001, "TCP"):
("192.168.1.10", 49152),
("203.0.113.5", 40002, "TCP"):
("192.168.1.11", 49152),
}
public_packet = ("203.0.113.5", 40002, "TCP")
private_host = translations[public_packet]
print(f"Forward reply to {private_host[0]}:{private_host[1]}")The router must allocate an unused translated port. If the public address has no available ports, it cannot create another mapping, even when private addresses remain available.
Exercise
Two hosts use 192.168.1.10:5000 and 192.168.1.11:5000 for TCP connections. Can both share public address 203.0.113.5 through PAT? What must differ?
Show answer
Yes. Their translated public port numbers must differ, such as 41000 and 41001. The public address-port pairs must be unique.