Definition NAT(Network Address Translation)

NAT helps to make computer networks use a range of unique addresses (private IPs) and connect to the Internet using a single IP address (public IP). Thanks to this “patch,” large companies would only use an IP address and not as many as there were machines in that company. You can also use NAT to connect home networks to the Internet.

 In the beginning, the Internet was not an extensive network, 32 bits were reserved “only” for addresses, the equivalent of 4,294,967,296 unique addresses, but the fact is that the number of machines connected to the Internet increased exponentially and the IP addresses were running out. For this reason, NAT or Network Address Translation emerged.

How does it work?

In NAT, there are several types of operation:

Static

A private IP address always translates to the same public IP address. This mode of operation would allow a host within the network to be visible from the Internet.

Dynamic

The router is assigned multiple public IP addresses. Each private IP address gets mapped using one of the public IP addresses. That the router is assigned so that each IP address corresponds to at least one public IP address.

Every time a host requires an Internet connection. The router will assign it a public IP address that is not in use. This time security gets increased since it makes it difficult for an external host to enter the network since public IP addresses are changing.

Overload

NAT with overload or PAT (Port Address Translation) is the most common of all types since we use it in homes. Multiple private IP addresses can get mapped through one public IP address, so we avoid hiring more than one public IP address. In addition to the economic savings, you can also save IPv4 addresses, since although the subnet has many machines, they all go to the Internet through the same public IP address.

The router uses the ports. In the TCP and UDP protocols, there are 65,536 ports to establish connections. So when a machine wants to establish a connection, the router saves its private IP and source port and associates them with the public IP and a random port. When information arrives at this randomly chosen port, the router checks the table and forwards it to the corresponding private IP and port.

Overlap

When a private IP address on a network is a public IP address in use, the router is responsible for replacing that IP address with another to avoid address conflict.

Advantages of NAT

The use of NAT has several advantages:

The first and most obvious one, the significant saving in IPv4 addresses. Let’s remember that we can connect multiple machines on a network to the Internet using a single public IP address.

Security

Machines connected to the network using NAT are not visible from the outside. So an outside attacker could not find out whether there is a connection in the device and the network.

Network maintenance

It would only be necessary to modify the forwarding table of a router to divert all the traffic to another machine while carrying out maintenance tasks.

Disadvantages of NAT

NAT is only a patch, not a solution to the real problem; therefore, it also has a series of difficulties associated with its use:

TCP and UDP Checksums

The router has to recalculate the checksum of each packet it modifies. So more computing power is needed.

Not all applications and protocols are NAT compatible. Some protocols introduce the source port into the data zone of a packet. So the router does not modify it, and the application does not work correctly.