What is port forwarding in a computer network and how to enable it on a network router?
Have you ever thought of exposing a service to the outer world, that is running over an internal LAN computer? It can be a web service or any other. One option is to configure a new public IP on the machine and let the cable plugin connects to the ISP. Looks a little difficult as it needs to get a new public IP. What if there are many such services needed?
Port forwarding in computer networking enables access to a service from anywhere that runs on an internal machine. For example, if you have a live website on a LAN machine with an internal IP (e.g 192.168.1.4). Now, this website needs to access via the internet.
Once you enable port forwarding on the LAN router, the internal website will be accessible from any corner of the globe.
The port forwarding is not limited to the internal LAN only. It could be any other IP.
How does port forwarding work?
The user needs to use the public IP address of the router with an optional port number (if other than default port 80). Internet routes request to the public router. Router checks if there is any port forwarding configured for a received destination port number. If not, the request may be dropped or handled by the router itself.
Once found a port forwarding entry, the router replaces the destination IP address with the new address (e.g LAN IP ) and forwards it to the local machine. In a message from the local machine to the client, the router sets the public IP in the source address.
The user feels that the service is running on public IP. There can be many such services on the same local machine with different port numbers.
How to configure port forwarding?
Port forwarding is a concept in networking. How to configure it depends on the brand of router you are using. Here are a few examples. Even with Linux, you can also configure the same if it works as a gateway.