IONOTS

Making Internet possible with Public IP and Private IP

In this article, you will learn about how the internet works under NAT connection and what is Public IP and How ports are used for packet transfer.

Public IP

A public IP address is an IP address that can be accessed over the Internet.

Example: A postal code of your town is unique over the country. In the same way, your public IP is unique over the internet (World Wide)

You can check your public IP by accessing your router admin panel or by searching ‘MY IP’ on google.

The above picture shows how a public IP is distributed as a private IP by NAT- Network Address Translation by the Switch(wifi router). But notice that when we ask google for ‘whats my IP’ the IP is the same for all the devices which is a Public IP address. From this, we can confirm that the server will get our Public IP address whenever we send a request packet and it will send packets back to our public IP.

But how exactly these Individual reply packets are distributed to Devices on private IPs as per their request?  To understand that we have to know the use of port numbers.

Note: Not every computer or home network has a public IP. Ask your ISP whether you have a public IP or private IP (under NAT). Internet Service providers take a PublicIP address and share them to a number of private IPs and distribute each private IP to a particular house/office network.

Ports

     NOTE:     192.168.0.X: XXXX — {145.12.14.6:XXXX} — 172.217.166.100:80 

                           PrivateIP:Port  —{Our Public IP: port} — destination IP: port

 

In the above picture, every PC is sending a request packet to a destination IP which is a google server IP 172.217.166.100:80 (PublicIP: Port number). And at the same time, every device opens a port on its socket to accept the packet on that port when the reply packet is received.

All these packets are 1st reached to the gateway of the network ie., Wifi Router and it manages these packets by storing their source IP and port number in a Router Table and then changes the source IP to the public IP address of our network and also changes the source port of each packet(PAT-Port Address Translation ) without disturbing the destination IP: Port number and then they were sent out of our network the server.

In the below table 192.168.0.142 and 192.168.0.140 requested the same ports. This is managed by Switch(wifi Router) as shown below.

 

 

Now the packets are reached to the server with different data in the packet but the destination IP of each packet is the same(145.12.14.6) but port number is different. The server processes the data in each packet and sends the reply back to our network IP with there respective port numbers (Our Public IP: Port).

Now our WiFi router receives the data and distributes them back to the private IPs with their respective port numbers(device Private IP: port) which are previously stored in the Router.

 

–ABHIJITH

Share this post

Share on facebook
Share on twitter
Share on linkedin
Share on email
Share on whatsapp