NAT and PAT basics: static NAT, dynamic NAT and port address translation
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- Private addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) are not routed on the Internet. NAT changes the source IP of an outgoing packet to a public address and translates the destination back in the reply.
- Static NAT: one inside address is permanently mapped to one public address (1:1). Used when an inside server must be reachable from outside.
- Dynamic NAT: an ACL defines which hosts are translated, and a pool defines which public addresses they are translated to. When the pool runs out, new hosts cannot get out.
- PAT (NAT overload): many inside hosts share one public IP; the router tells the connections apart by port number.
- NAT is not a security mechanism: security comes from ACLs, firewalls, IPS and policies. Some applications that carry IP addresses inside the packet (for example IPsec, FTP) can have trouble with NAT.
The problem: a private address cannot reach the Internet
Without NAT (Network Address Translation) and PAT (Port Address Translation), probably only one device at home could access the Internet.
On the left, in the inside network (LAN), there is a computer with IP address 10.50.0.11 connected to a router. The ISP gave us one public address: 203.0.113.11. On the Internet there is a server with address 198.51.100.20.
When the computer sends a packet to the server, the source is the computer (10.50.0.11) and the destination is the server (198.51.100.20). When the server replies, it puts its own IP as the source and the computer's IP as the destination.
There is one problem with this example: the computer's address is a private address. Private addresses are meant for inside networks, public addresses for the Internet. The ISP will drop traffic with a private source.
| Private address range (RFC 1918) | Prefix |
|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0 /8 |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0 /12 |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0 /16 |
In these lessons we use the 203.0.113.0 /24 and 198.51.100.0 /24 ranges as public addresses. These ranges are reserved for documentation and examples and belong to nobody on the real Internet.
Static NAT step by step
Now the router is configured for NAT: address 10.50.0.11 must be translated to 203.0.113.11.
1. The packet goes out. The computer again sends a packet to the server: source 10.50.0.11, destination 198.51.100.20. The NAT router changes the packet's source IP from 10.50.0.11 to 203.0.113.11 and remembers this translation in its NAT table.
2. The server replies. The server thinks it is talking to 203.0.113.11. So the destination in its reply is 203.0.113.11.
3. The packet is translated back. When the reply reaches the NAT router, the router checks its NAT table again, translates the destination 203.0.113.11 back to 10.50.0.11 and sends the packet to the computer.
This example is called static NAT: there is a permanent 1:1 relationship between the inside computer's address and the address from the ISP. Because the mapping is permanent, connections can also be started from outside to this address. That makes static NAT useful for inside servers that must be reachable from outside (a web server, for example).
Dynamic NAT
What if there are more computers inside? Then we can use dynamic NAT. Dynamic NAT differs from static NAT because:
- A pool of public addresses is used for the translation.
- An access-list selects which inside hosts are translated.
Suppose the ISP gave us a whole range instead of a single address, and we use part of it, 203.0.113.100 – 203.0.113.110, as a pool.
- 10.50.0.11 visits a server on the Internet. The NAT router translates it to the first address in the pool, 203.0.113.100.
- The next computer, 10.50.0.12, goes to the Internet. The router translates it to the second address in the pool, 203.0.113.101.
- The third computer, 10.50.0.13, gets 203.0.113.102.
- And so on.
This is dynamic NAT. The translation is still 1:1: each inside host gets its own public address. The difference is that which address it gets is not fixed in advance. When no free address is left in the pool, a new host cannot be translated and the router drops the packet.
PAT: one public IP, many hosts
You probably have several devices at home or in the office that access the Internet, but only one public IP from the ISP. How does that work?
This is where PAT (Port Address Translation) comes in. NAT only creates a 1:1 relationship between two IP addresses. With many computers inside and one IP from the ISP, we need to translate port numbers as well.
First let's see what happens without PAT. There are two computers inside: 10.50.0.11 and 10.50.0.12. The router is configured for plain NAT:
- 10.50.0.11 connects to the server.
- The NAT router translates 10.50.0.11 to 203.0.113.1.
- 10.50.0.12 also wants to connect to the server.
- The router has a problem: 203.0.113.1 is already given to 10.50.0.11, and the same address cannot be given 1:1 to two hosts.
With PAT, this is what happens:
- 10.50.0.11 connects to the server.
- The NAT router translates 10.50.0.11 to 203.0.113.1 and also keeps track of the source and destination ports.
- 10.50.0.12 also connects to the server.
- Because the router does PAT, it translates 10.50.0.12 to 203.0.113.1 as well, but tells the connection apart by a different port number.
According to Cisco's training materials, PAT first tries to keep the host's original source port. If that port is already in use, the router picks another free port number.
This way all inside computers can reach the Internet behind the one public IP from the ISP. Another name for PAT is NAT overload.
| Type | Relationship | What you need | When |
|---|---|---|---|
| Static NAT | 1 inside ↔ 1 public, permanent | One public IP per host | Inside server reachable from outside |
| Dynamic NAT | 1 inside ↔ 1 public, from a pool | Pool of public IPs + ACL | When you have several public IPs |
| PAT (overload) | Many inside ↔ 1 public, by port | One public IP + ACL | Homes and offices: the most common |
Does NAT mean security?
The server thinks it is only talking to 203.0.113.1; it has no idea there are hosts 10.50.0.11 or 10.50.0.12 inside. Does that make NAT a security protocol?
No. Not seeing the real addresses of inside hosts does not mean you cannot connect to them: as long as the router is translating, those hosts are reachable. Security is built with access-lists, firewalls, IPS (intrusion prevention systems) and security policies.
Because NAT and PAT change the IP packet, some applications don't work well with this translation, especially those that carry the IP address inside the packet. IPsec is an example, and FTP can also cause trouble behind a NAT router.
Exam note: NAT is in the IP Services section of the CCNA 200-301 exam: you need to be able to configure and verify inside source NAT using static NAT and pools.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1What does a NAT router change in an outgoing packet?
2Which address is in a private range?
3An inside web server must always be reachable from outside with the same public address. Which type of NAT fits?
4An office has 50 computers and the ISP gave one public IP. What is needed?
5Is NAT a security mechanism?
Comments
Sign in to comment.