DEV Community

Madhukar
Madhukar

Posted on

Public IP, Private IP and Port forwarding

What is a public IP?
• A public IP is an IP address that is exposed to external world i.e internet (global)

What is a private IP?
• A private IP is an IP address that is exposed with in the local network (local)

I know the above two statements sound so cryptic. To get a clear understanding of the above two statements let us do a small activity.

  1. Take any two electornic devices, connect to your home WiFi and simply type my IP in Google search tab.

  2. Now you see the public IP address down to your search tab with a small heading as "your public IP address" (eg: 167.155.187.34)

  3. You must have noticed that on both the screen's you see the same public IP

Wondered , right! When IP addresses are unique, how come same IP🤔

It's a simple funda... Really?? Yes 😁

See, to expose every device directly on to internet it is really impossible instead what your ISP does is, it gives a public IP to your router and all the machines hooked up to your router will get one IP which is known as internal IP.

Okay....🤔. For example if I want to expose an application running on one of the local machine to the outside world what should I do??

To do this task you have many techniques. one of them is port forwarding. Before we try to understand what is port forwarding let's try to understand the below scenarios.

• If you are in the same network where your application is running you can very well access it.

• Now if you are outside to the network where your application is running then if you try to access it with the internal IP you'll end up playing the Google's Dinosaur game and trying to crack the previous best.

• Now if you work around with the public IP (can be taken from your routers settings, known as WAN IP. WAN IP is a translation of IP address that you found on Google a moment ago) by concatenating Port number will still land you on the Google's Dinosaur game page. Because, your router has no idea what that application is.

Upon understanding the above scenarios, now it's the right time to understand what is port forwarding.

Port forwarding is a process of training your router that any request comes with a specific port number (eg:8080). It need to be routed to some device (eg:AD) with some internal IP (eg:192.168.0.178).

Okay...🤔🤔.But how does it work if I want to do this for multiple applications with different port numbers in the same network ???

Your router internally maintains a routing table (usually a hash table) where the port number is mapped with the internal IP address and the story remains same in routing the request.

Thank you for taking time to read this blog 😊

Credits goes to Hussein Nasser

Top comments (0)