Network Address Translation (NAT) - GeeksforGeeks

Network Address Translation (NAT)

Last Updated : 13 Dec, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

To access the Internet, one public IP address is needed, but we can use a private IP address in our private network. The idea of NAT is to allow multiple devices to access the Internet through a single public address. To achieve this, the translation of a private IP address to a public IP address is required. Network Address Translation (NAT) is a process in which one or more local IP address is translated into one or more Global IP address and vice versa in order to provide Internet access to the local hosts. Also, it does the translation of port numbers i.e. masks the port number of the host with another port number, in the packet that will be routed to the destination. It then makes the corresponding entries of IP address and port number in the NAT table. NAT generally operates on a router or firewall. 

Network Address Translation (NAT) working – 
Generally, the border router is configured for NAT i.e the router which has one interface in the local (inside) network and one interface in the global (outside) network. When a packet traverse outside the local (inside) network, then NAT converts that local (private) IP address to a global (public) IP address. When a packet enters the local network, the global (public) IP address is converted to a local (private) IP address. 

If NAT runs out of addresses, i.e., no address is left in the pool configured then the packets will be dropped and an Internet Control Message Protocol (ICMP) host unreachable packet to the destination is sent. 

Why mask port numbers ?   
Suppose, in a network, two hosts A and B are connected. Now, both of them request for the same destination, on the same port number, say 1000, on the host side, at the same time. If NAT does only translation of IP addresses, then when their packets will arrive at the NAT, both of their IP addresses would be masked by the public IP address of the network and sent to the destination. Destination will send replies to the public IP address of the router. Thus, on receiving a reply, it will be unclear to NAT as to which reply belongs to which host (because source port numbers for both A and B are the same). Hence, to avoid such a problem, NAT masks the source port number as well and makes an entry in the NAT table. 

NAT inside and outside addresses – 
Inside refers to the addresses which must be translated. Outside refers to the addresses which are not in control of an organization. These are the network Addresses in which the translation of the addresses will be done.

  • Inside local address – An IP address that is assigned to a host on the Inside (local) network. The address is probably not an IP address assigned by the service provider i.e., these are private IP addresses. This is the inside host seen from the inside network. 
     
  • Inside global address – IP address that represents one or more inside local IP addresses to the outside world. This is the inside host as seen from the outside network. 
     
  • Outside local address – This is the actual IP address of the destination host in the local network after translation. 
     
  • Outside global address – This is the outside host as seen from the outside network. It is the IP address of the outside destination host before translation. 
     

Network Address Translation (NAT) Types – 
There are 3 ways to configure NAT: 
 

  1. Static NAT – In this, a single unregistered (Private) IP address is mapped with a legally registered (Public) IP address i.e one-to-one mapping between local and global addresses. This is generally used for Web hosting. These are not used in organizations as there are many devices that will need Internet access and to provide Internet access, a public IP address is needed. 

    Suppose, if there are 3000 devices that need access to the Internet, the organization has to buy 3000 public addresses that will be very costly. 
     

  2. Dynamic NAT – In this type of NAT, an unregistered IP address is translated into a registered (Public) IP address from a pool of public IP addresses. If the IP address of the pool is not free, then the packet will be dropped as only a fixed number of private IP addresses can be translated to public addresses. 

    Suppose, if there is a pool of 2 public IP addresses then only 2 private IP addresses can be translated at a given time. If 3rd private IP address wants to access the Internet then the packet will be dropped therefore many private IP addresses are mapped to a pool of public IP addresses. NAT is used when the number of users who want to access the Internet is fixed. This is also very costly as the organization has to buy many global IP addresses to make a pool. 
     

  3. Port Address Translation (PAT) – This is also known as NAT overload. In this, many local (private) IP addresses can be translated to a single registered IP address. Port numbers are used to distinguish the traffic i.e., which traffic belongs to which IP address. This is most frequently used as it is cost-effective as thousands of users can be connected to the Internet by using only one real global (public) IP address. 
     

Advantages of NAT – 
 

  • NAT conserves legally registered IP addresses. 
     
  • It provides privacy as the device’s IP address, sending and receiving the traffic, will be hidden. 
     
  • Eliminates address renumbering when a network evolves. 
     

Disadvantage of NAT – 
 

  • Translation results in switching path delays. 
     
  • Certain applications will not function while NAT is enabled. 
     
  • Complicates tunneling protocols such as IPsec. 
     
  • Also, the router being a network layer device, should not tamper with port numbers(transport layer) but it has to do so because of NAT. 
     

 


Previous Article
Next Article

Similar Reads

Difference Between Network Address Translation (NAT) and Port Address Translation (PAT)
Network Address Translation (NAT): NAT, in which the Private IP address or local address is translated into the public IP address. NAT is used to slow down the rate of depletion of the available IP addresses by translating the local IP or Private IP address into a global or public IP address. NAT can be a one-to-one relation or many-to-one relation
4 min read
Types of Network Address Translation (NAT)
Prerequisite - Network address translation (NAT) Network Address Translation (NAT) is a process in which one or more local IP address is translated into one or more Global IP address and vice versa in order to provide Internet access to the local hosts. NAT generally operates on a router or firewall. Network address translation (NAT) working - Gene
4 min read
Advanced NAT Techniques: Port Address Translation (PAT)
Network Address Translation (NAT) is a networking technique used in routers to modify network address information in packet headers while in transit, Its main purpose is to enable the conservation of public IP addresses and facilitate communication between devices in private or local networks and the public Internet. now a days NAT is commonly impl
6 min read
Why is the IP address called a "logical" address, and the MAC address is called a "physical" address?
Let us try to deeply understand, why IP address is known as "Logical" while, MAC Address is known as "Physical" address. The IP address and the MAC address are both used for addressing and identifying devices on a computer network, but they serve different purposes and operate at different levels of the network stack. An IP address is a logical add
7 min read
IP address as logical address and MAC address as Physical address
Overview :IP addresses and MAC addresses are essential for data communication. Assume there are two networks. The first network has three devices: A, B, C and the second network has three devices: X, Y, Z. If a device A from the first network wishes to send data to a device Y in the second network, it must first determine where Y is located in the
6 min read
Difference Between Network Address Translation and Domain Name System
NAT stands for Network Address Translation. NAT is a technique used to connect networks together, it is typically used when a device on a private network wants to communicate with a device on a public network, such as the internet. NAT operates on a router, which is responsible for replacing the private IP addresses of devices in a local network wi
3 min read
Port Address Translation (PAT) on Adaptive Security Appliance (ASA)
Port Address Translation (PAT) is a type of Network address translation (NAT) used when there is a shortage of public IP addresses .One of the public IP address of the same subnet or the interface address is used for translation. Port Address Translation (PAT): This is also known as NAT overload. In this, many local (private) IP addresses get trans
5 min read
Port Address Translation (PAT) mapping to Private IPs
In this article we will be learning how exactly a Home network works. In the beginning we should keep in mind that when we connect our Laptops, Smart Phones Tablets etc to the home network all get a IP address. This IP address which is assigned to these devices is not public IP address rather they are private IP address. This home network is a Loca
4 min read
NAT Hole Punching in Computer Network
Prerequisite - Network Address Translation (NAT) What is NAT hole punching ? The main restriction or disadvantage for a Device under a NAT is that it cannot accept outbound connections. And if any such attempt is made a NAT makes sure that the message reaches the trash can. This restriction is overcome a method known as Hole Punching. In this metho
3 min read
Why Star network is More Efficient in Network Fault Tolerance in Place of Bus Network?
Answer: Star networks offer better fault tolerance than bus networks because a single point of failure in a star network (the central hub) affects only the connected device, while a fault in a bus network can disrupt communication for all devices on the bus.Advantages of Star Topology Over Bus Topology Individual Connection Points: In a star networ
2 min read
Article Tags :