Every device that connects to an internet has a set of number given to it, which is called it’s IP. Basically IP is like an address for that device in the city of Internet.
Now that device can run several different type of software services, like mail, browse internet, remote desktop to another device, gaming, etc. So for each of this services to talk through internet, obviously they connect through IP, but also through the specific port (like specific channel for that software service). For example when you browse Google.com you are making connection to the Google.com server’s IP address and port 80 if you are making http request or port 443 if you are making https request.
Now let’s say in your home, you got a router with public IP address. Public IP address means you can reach that device from anywhere in the internet using its public IP. Your other home devices like laptop or phone will get private IP’s as allocated by your router. You can run a webserver in your laptop but since your laptop’s IP is private, you can’t access that website from internet. But you have a public IP in your router so what you can do is create configuration on router which says any request coming to this router at port 80 goes to your laptop (specify it’s private IP) and it’s port 80.
Bow when you access your routers public.ip:80 from internet, the request will reach your router and since router has the forwarding configuration, it will forward that request to your laptop.
Let’s say you have another website running in another laptop. You can configure another port forwarding setting in router which says port 81 request goes to another laptop’s private ip with port 80(webserver runs through 80 by default).
Now from internet if you go to public.ip:80 it will open up website from first laptop, but if you do public.ip:81 it will open up website from second laptop.
TLDR – ports are like channel number we give to software services. Any device that can receive request on one port can forward that request to another device at different or same port.
Latest Answers