It's important first to know how Network Address Translation (NAT) works. You establish a connection to a server on the internet. In reality you send packets to your router, going out from your computer on some randomly chosen port:
Your computer Router
╔════════════╗ ╔═══════════╗
║ ║ ║ ║
║ port 31746 ╫====>╫ ║
║ ║ ║ ║
╚════════════╝ ╚═══════════╝
Your router, in turn, establishes a connection to the server you want to talk to. It talks out it's own randomly chosen port:
Router www.google.com
╔═══════════╗ ╔════════════════╗
║ ║ ║ ║
║ port 21283╫====>╫ port 80 ║
║ ║ ║ ║
╚═══════════╝ ╚════════════════╝
When Google's webserver sends you back information, it is actually sending it back to your router (since your router is the guy actually on the Internet):
Router www.google.com
╔═══════════╗ ╔════════════════╗
║ ║ ║ ║
║ port 21283╫˂====╫ port 80 ║
║ ║ ║ ║
╚═══════════╝ ╚════════════════╝
A packet arrives at your router, on port 21283
from www.google.com
. What should the router do with it?
In this case the router has kept a record of you, and it knows that any traffic arriving on port 21283
from the Internet should go to your PC. So the router will relay the packet to your computer:
Your computer Router
╔════════════╗ ╔═══════════╗
║ ║ ║ ║
║ port 31746 ╫<════╫ ║
║ ║ ║ ║
╚════════════╝ ╚═══════════╝
Open NAT (aka Full cone NAT, aka the good, right, and correct one)
In open NAT, any machine on the internet can send traffic to your router's port 21283
, and the packet will be sent back to you:
Your computer Router
╔════════════╗ ╔═══════════╗ ╭www.google.com:80
║ ║ ║ ║ ├www.google.com:443
║ port 31746 ╫<════╫ port 21283╫<════╡serverfault.com:80
║ ║ ║ ║ ├fbi.gov:32188
╚════════════╝ ╚═══════════╝ ╰botnet.cn:11288
Moderate NAT (aka Restricted Cone NAT)
Moderate NAT is where your router will only accept traffic from the same host, but will allow it to come from any port:
Your computer Router
╔════════════╗ ╔═══════════╗
║ ║ ║ ║ ╭www.google.com:80
║ port 31746 ╫<════╣ port 21283╫<════╡www.google.com:443
║ ║ ║ ║ (rejected) serverfault.com:80
╚════════════╝ ╚═══════════╝ (rejected) fbi.gov:32188
(rejected) botnet.cn:11288
Closed NAT (aka Port-restricted cone NAT)
Closed NAT is more restrictive. It won't allow anything in unless it came from the original host and port that you originally communicated with, i.e. www.google
port 80
:
Your computer Router
╔════════════╗ ╔═══════════╗ ╭www.google.com:80
║ ║ ║ ║ ┆ (rejected) www.google.com:443
║ port 31746 ╫<════╫ port 21283╫<════╛ (rejected) serverfault.com:80
║ ║ ║ ║ (rejected) fbi.gov:32188
╚════════════╝ ╚═══════════╝ (rejected) botnet.cn:11288
Teredo, X-Box Live, NAT
Microsoft's book Writing Secure Code has some other definitions of the different types of NAT. It is written in the context of NAT for use by Teredo; the IPv6 transition technology:
- Full cone: A full-cone NAT establishes an external UDP port when sending an outbound packet and will forward traffic sent to that port from any IP address and any port back to the originating port on the internal system.
- Restricted cone: This type of NAT maintains some level of state and requires that replies come from the same IP address as the initial request was sent to.
- Port-restricted cone: Replies must come from the same IP address and port as the request.
- Symmetric: In addition to the requirements for a port-restricted code NAT, the symmetric NAT will create a new mapping of internal IP address and port to external IP address and port for traffic sent to every individual external host.
Some newer NAT devices can also appear to be port restricted under some conditions and symmetric under others:
In particular, we found that many NAT have a 5th strategy, "port conservation." Basically, they will try to keep the same port number inside and outside, unless it is already used for another connection, in which case they pick a different one either sequentially (from a global variable) or randombly. These NATs appear typically "port restricted" during the tests, but behave as "symmetric" under load. (Huitema, personal communication)
If you're interested in the details, consult RFC 3489 (Rosenberg et al. 2003).
Remember: if anyone tries to tell you that Full-code NAT/Open NAT is a security issue, tell them they don't know what they're talking about. NAT is not a security boundary - that is what a firewall is. Anyone using NAT as a security boundary is simply wrong.
See also