NAT stands for Network Address Translation. The router uses it to translate a private IP address to a public IP address, and vice versa.
Since there's a small number of IP addresses available in IPV4 (2^32 ~= 4.3 billion) as compared to the number of devices connected to the internet, the scheme of internal mapping is required where multiple devices are mapped to one public IP. Internally, each device is assigned a private IP from the reserved private space of 10.0.0.0/8
.
When the device wants to communicate to the internet, it sets the source IP address to its internal private IP address and routes the packet to the NAT server.
Usually, the NAT is installed on the router, where the router’s interface is connected to the internet via a public IP address. The NAT server replaces the source IP address of the packet with its public IP address and makes an entry in the NAT table against this mapping.
Let's say a packet is sent from the PC 6 to any network X, as shown below. Here, the header of the packet contains the source address 10.0.0.6
with the port 3300
, and the destination address 192.168.1.10
with port 78
. This reaches the router where the NAT makes updates to the packet. An example of the packet traversing the NAT-based router before its transmission to the internet has been given below.
As shown above, when a packet is received at the router, the NAT replaces the source address 1.0.0.6
with its public IP address 85.13.217.9
. NAT also replaces the source port number 3300
with a new port number 5454
that is available at the NAT’s public interface.
When the target device responds, the NAT translation table assists us in identifying the local address of the destination device. The target device sends a packet to the router with the destination address 85.13.217.9
and port 5454
. NAT consults the NAT-table against the entry 85.13.217.9
,5454
and replaces the destination IP and port number in the incoming packet with 1.0.0.6
and 3300
, respectively. The packet is then routed internally to the destination host.
Free Resources