NAT traversal: Introduction

Translation of the original in Catalan. Read it in: CatalàCastellano

Part 1 of 3NAT traversal
  1. NAT traversal: Introduction
  2. NAT traversal: How does STUN work?
  3. NAT traversal: How does ICE work?

Nowadays it's very common to have networks behind

gateways

(routers, firewalls, etc) that through

NAT

give the hosts access to the internet, we often call

masquerading

this feature which is nothing but a subset of the functions of

NAT

itself. Most problems associated with internet access via masquerading are solved. But when the problem we have is the reverse, that is, we want to access, via TCP or UDP, a host that is inside a network with a gateway doing NAT, the thing gets complicated.

In fact, if what we want is to redirect a port of the public IP with which the internet is accessed to an internal host there isn't too much mystery to it either, thanks to DNAT. But if these redirections have to be to more than one host we often have to start using not very standard ports to offer services that are inside the network and that we want to publish on the internet. In other words, the only thing we can do a priori is statically map ports of the public IP to certain ports of the private IPs.

In order to be able to receive connections on a host that is behind a gateway doing NAT there are a series of more or less (un)known techniques.

  • TURN (****Traversal Using Relay NAT): the idea is to have a pool of public IPs so that the applications that need to be published on the internet take an available IP temporarily or permanently to publish that service on that IP which will map its ports. In other words, it's based on an idea similar to DNAT but it adds the ability to use pools of IPs dynamically.
  • STUN (Session Traversal Utilities for NAT): It's aimed at VoIP, messaging, videoconferencing applications, etc. Often the connections STUN is used for are via UDP, although there can also be STUN servers that work with TCP or even TCP/TLS. The STUN protocol is a very lightweight client-server protocol.
  • ICE (Interactive Connectivity Establishment): finally the idea of ICE is to look for the best route between two hosts that want to communicate. If both are inside the same LAN or in different LANs but have public IPs or static NATs (1to1), then it routes the connections and that's it. But if the hosts are behind NAT doing dynamic masquerading then it uses combinations of the STUN and TURN techniques.

In order to understand these problems better it's necessary to be clear about the types of NAT that exist:

  • Full Cone NAT
  • Port Restricted Cone NAT
  • Restricted Cone NAT
  • Symetric NAT