IPv4 addresses are made up of 32 bits and allow for a total of 4,294,967,296 addresses to be created. Initially, it was thought that this number would be enough to assign one to each device in the world. However, with the boom of the Internet, the demand increased so much that this amount proved to be insufficient. The number of available IPs was much smaller than the number of devices connecting to the Internet.
To address this issue, various provisional strategies were implemented:
- Reserving some blocks of addresses (private addresses)
- Use of Classless Inter-Domain Routing (CIDR)
- NAT (Network Address Translation)
The IPv4 protocol allowed nodes or hosts to connect to the Internet using public IPs. Companies and organizations would request address blocks from the corresponding RIR, which would assign blocks as needed. Public IPs are routable on the Internet, whereas private IPs are not and can be used without formal authorization.
How NAT Works
NAT stands for Network Address Translation. Its function is to translate a private IP address to a public IP address and vice versa. This is essential for devices with private IPs to communicate over the Internet. But why not use public IPs directly?
- Provisionally solves the IPv4 exhaustion problem.
- Reduces the high cost of obtaining public IPs.
- Allows connecting thousands of devices to the Internet using a single public IP address.
For example, if a PC with a local IP (192.168.1.30) wants to send a packet to the Internet, the DHCP sends the IP to the NAT to translate it to a public IP and go out to the Internet. Upon returning, the NAT translates the public IP back to private and sends it to the device.
Most routers in homes and businesses use NAT to translate the private IPs of each device to the public IP assigned by their ISP or RIR.
Types of NAT
Static NAT: Always translates a private address to the same public address, manually configured. Useful for devices needing a fixed address accessible from the Internet, such as web servers, although it poses security risks.
Dynamic NAT: Assigns public IP addresses from a pool to private addresses. It can assign multiple public IPs, hiding internal LAN addresses.
NAT Overloading: Allows multiple devices to use a single public IP through port translation (TCP and UDP). The router associates origin ports with public IPs and random ports.
Port Address Translation (PAT): Allows multiple private IPs to connect to the Internet using a single public IP, translating through ports. Offers greater security and is ideal for small local networks.
Advantages of NAT
- Conserves IPv4 addresses, enabling multiple devices with a single public IP.
- Simple configuration and low maintenance.
- Provides a layer of security as devices on the local network are not visible from the outside.
- Compatible with most current communication protocols (TCP and UDP).
Disadvantages of NAT
- Requires higher processing power from the router.
- Can degrade performance and increase latency.
- Incompatible with some higher-layer protocols.
- Makes end-to-end IP tracking and remote troubleshooting difficult.
- Can negatively impact online gaming.
NAT vs. IPv6
NAT is a provisional, not definitive solution to the IP address exhaustion issue. Although it allows for flexible local network creation, it has its drawbacks. IPv6, with a larger number of available IPs, is the definitive solution. It allows any node to have a public IP address, solving end-to-end connectivity problems and providing built-in security mechanisms.
With the adoption of IPv6, the need for NAT would decrease, enabling better connectivity and security on the Internet. However, the transition to IPv6 is a long and gradual process that is still ongoing.