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 Local Area Network.
Use of Private IP in Home Networks:
The Private IP are not registered thus it cannot be used to find a user uniquely over the internet. The private IP are usually in the range 192.168.X.X and 10.X.X.X . These private IP are assigned by the routers to each device which is connected to the router.
So, then How our devices connected to the internet is the Private addresses assigned to them cannot be uniquely identified over the internet ?
This is where Port Address Translation (PAT) or more commonly known as Network Address Translation Overload comes in to the picture.
An important thing to keep in mind that the only our router which is connected to Internet is given a Public IP.
Thus, all devices in the LAN communicate with the internet using only one Public IP.
Necessity of Private IPs in LAN :
To conserve the available IPv4 addresses each device in the Home network is not assigned a public address thus we have to use PAT.
Port Address Translation (PAT):
This solves the problem of how devices with private IP address would connect to the Internet using single Public address which is assigned to the edge router.
Steps in Private IP resolution :
- When a device in the private network wants to connect to a website then it does all the steps as per the OSI model in the device itself (an IP packet is created) and then gives the IP packet to the Router present in the Home network.
- The Port Address Translation is implemented in the router.
So, now the IP packet received by the router has a Private IP and a Port number(given by our computer) so now the router will substitute the private IP with the Public IP of the router and specific port is assigned to that connection of that device.
- An entry is created in the Translational Table mapping which private IP and Port is mapped to which Public IP and Port of the router.
- Thus finally in the port field of IP packet is replaced by the new port number assigned by the Router.
- The packet is routed in the internet as per the networking rules.
- The entry in Translation Table is made only first time when the connection is established between a specific host to another specific destination host.
- The destination IP and destination Port are not changed.
Reply IP packet by Destination Host:
The destination host replies back and in the reply IP packet the destination IP address is the Router Public Address and Port number is the port number assigned by the router for that specific connection in that specific device.
How finally the IP packet is given back to that particular device which had asked for that response from that specific website ?
- The particular device can be found by looking into the network address translation (NAT) table, as we had received the IP packet in the specific port of the edge router.
- By checking the corresponding Translation Table entry with assigned port number and (actual destination host)destination IP address(from where the IP packet is coming) we can find uniquely the device and particular port of that specific device.
What if all the devices in the Private network want to connect to the same destination Host and to the same port of the destination Host ?
There is no problem because in the translation table there would be entry for each this kind of connection. The connections can be distinguished from on another by the fact that each connection is given a unique port number by the Router.
The whole above concept will be clear with the below diagram.
The Translation Table Looks like (the entry is w.r.t above example IP addresses):-
In, this way using only one Public IP we can connect our devices in Private network to the Internet.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.