Hello Everyone, Recently, I came across a topic is NAT and, this felt so interesting so I wanted to share what is NAT and, how does it work.
So what we will be discussing in this post is :
what is NAT
1.How NAT came in to picture and a little history
2.How NAT works
3.Types of NAT
What is Network Address Translation (NAT)
NAT is used to enable multiple hosts on a private network to connect to the Internet using a single public IP address or we can say that the basic idea of NAT is to allow multiple devices to access the Internet through a single public address.
So basically, NAT helps a private network to communicate with the public network(Internet).
How NAT came in to picture and a little history
Back in 1994, there was a problem with IPV4 and the problem was the IP address was allocated based on the class. Class A address was given to big companies, smaller companies were given class B and smaller get class C address, and so on and, the main problem with this method was that millions of class A address were wasted, many of the class B address were wasted, whereas, number of addresses available in class C is so small that it cannot cater the needs of organizations.
The solution to this problem was to create several address ranges that are the private IP address like, 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 learn more about private IP. In this way, we were able to solve problems with classful addressing and this allows us to set up a network and pick one of these addresses to build our network. But again there was a problem that, this doesn’t allow us to communicate on the public internet because on the public internet we have to use the public IP address. That’s where NAT came in to picture and helps us to solve this problem by allowing us to communicate with the public internet.so let us see how NAT solves this problem.
Network address translation between a private network and the Internet.
Image credit: Wikipedia
So if we see in the above picture there is a host connected to a private network, a router most likely be configured to use NAT and, a server connected to the internet. if we want to send a message to the server from an internal device that is connected to a private network with the source address 10.0.0.1 and destination address 184.108.40.206
Now when we send this message out, the message will easily be transferred to the server because our router looks for the destination address which is 220.127.116.11
But what happens when the server responds? let’s find out. when the server wants to respond and now destination IP will be 10.0.0.10 and source IP will be 18.104.22.168, now when the server responds, we know private is address is not routable and the packet gets rejected and thrown away.
Here comes the use of NAT, when the server sent the message to the router which will be configured to use NAT, what it does that it takes source IP (10.0.0.1) and store it in a table(also known as NAT table) and replace it with public IP(22.214.171.124).
Now, if we send any message from private IP to the internet it will reach to the server and when the server responds destination IP will be 126.96.36.199 which is public and points to our router, once the router receives the message it looks in the NAT table and it removes the public IP 188.8.131.52 and replaces it with private address 10.0.0.10 and replaces it with private address 10.0.0.10 and forwards the message back to the device.
Types of NAT
A single private IP address is mapped with a public IP address and is generally used for Web hosting.
A private IP address is translated into a public IP address from a pool of public IP addresses.
Port Address Translation (PAT)
Many private IP addresses can be translated to a single registered IP address. Port numbers are used to distinguish the traffic.
That’s it, I hope it helps you in any way.
Stay home stay safe and happy learning