IP/Network

 

 

 

 

Port Forwarding

 

Port forwarding is a technique used in networking to allow external devices to access services or applications running on a local network.

 

Port forwarding is commonly used in scenarios where users want to host a website or a game server from their home network or to access network resources remotely.

 

 

 

How it works ?

 

when a device on the internet wants to communicate with a specific device or service on a private network, it sends a request to the router that connects the two networks. The router then uses port forwarding to direct the request to the correct device or service on the private network.

 

This is done by configuring the router to forward incoming traffic on a specific port to a specific device or service on the private network. This enables users to access services such as web servers, email servers, and game servers that are hosted on devices on the private network from anywhere on the internet.

 

 

Example :

 

Let's say you have a web server running on a computer in your local network, and you want to make it accessible to the internet so that people can access your website from anywhere.

 

Step 1: Find the IP address of the computer running the web server

    You need to find the local IP address of the computer running the web server. This can be done by opening the command prompt (Windows) or terminal (Mac/Linux) and typing "ipconfig" (Windows) or "ifconfig" (Mac/Linux). Look for the IPv4 address of the computer running the web server.

 

Step 2: Set up port forwarding on your router (NOTE : this router can be a specific router device or it can be a WiFi Access Pointer at your home).

    Next, you need to set up port forwarding on your router to allow external traffic to reach the web server. To do this, log in to your router's administration page (usually accessed by typing the router's IP address in a web browser) and look for the "Port Forwarding" or "Virtual Server" section.

     

    Here, you'll need to specify the following information: The specific items listed here may appear differently depending on the specific router that you are using, but you would figure out correct items if you have general understandings as decribed below.

     

    Service Name: Give the port forwarding rule a name (e.g. "Web Server").

    External Port: Specify the port that incoming traffic will use to access the web server (usually port 80 for HTTP or port 443 for HTTPS).

    Internal Port: Specify the port on the local network where the web server is running (usually port 80 or 443). If you are running your webserver (or any program that you want to get access from outside) at different port (e.g, 3000) put that port number.

    Internal IP Address: Specify the IP address of the computer running the web server that you found in Step 1.

    Protocol: Choose the protocol (TCP or UDP) that the web server uses.

    Save the changes to apply the port forwarding rule.

     

    Following is an example of the port forwarding setup dialog for WiFi Access Point (WiFi Router) at my home. It is highly likely that you would have difference interface at your home. Some WiFi Router may not support Port Forwarding and does not provide this kind of setup window.

 

Step 3: Test the web server

    Now that port forwarding is set up, you can test the web server by accessing it from a device outside of your local network. Open a web browser and type in the public IP address of your router followed by the external port you specified in Step 2 (e.g. http://<public IP address>:80). If everything is set up correctly, you should see your website.

 

I would suggest you to note that the public IP address of your router may change periodically, especially if you have a dynamic IP address from your internet service provider. In this case, you'll need to update the IP address in your port forwarding rule to reflect the new address. Some routers also offer Dynamic DNS services that allow you to assign a domain name to your router's IP address to make it easier to remember. (NOTE : Some Router allows you to allocated a fixed IP for the device (e.g, PC) that you chose. In that case, you don't need to worry that the internal IP address keep changing).

 

 

 

Difference between Port Forwarding and NAT (Network Address Translation)

 

Port forwarding and Network Address Translation (NAT) are related concepts but serve different purposes in networking.

 

NAT is a technique used to allow multiple devices on a private network to share a single public IP address. When a device on the private network sends a request to the internet, the NAT router replaces the private IP address with its public IP address so that the response from the internet can be sent back to the correct device on the private network.

 

Port forwarding, on the other hand, is a technique used to allow external devices to access services or applications running on a specific device on a private network. It works by configuring the router to forward incoming traffic on a specific port to a specific device or service on the private network.

 

In other words, NAT is used for general internet connectivity, while port forwarding is used for specific services or applications hosted on a device on the private network.

 

For example, if you have multiple devices on your home network sharing a single public IP address using NAT, port forwarding can be used to allow external devices to access a web server running on a specific device on the network.

 

In short, NAT is used to allow multiple devices on a private network to share a single public IP address, while port forwarding is used to allow external devices to access specific services or applications hosted on a device on the private network.

 

 

 

Reference