Thursday, November 20, 2014

The correct way to use Port Forwarding

What is Port Forwarding?

If you connect to the internet through a router, port forwarding could be very useful. The job of a router is to route the internet connection to the devices on the local network (PCs, laptops, smartphones, etc.). The devices on the local network are "behind the router". That is, when you try to open a website, the request goes to the router first and from the router to the remote server; similarly, when the remote server responds, the data comes to the router first and then to your device. Your router has a global IP address assigned by the ISP and your devices has a local IP address. The remote server knows you by your router's global IP address only and not your local IP address. When the data packet meant for your router arrives, the router has to effectively forward it to your device.

Servers listen for incoming connections on specified ports. If someone has to connect to a server, he has to use the global IP address. But it will lead him to the router and without telling the router where to forward the incoming connections they will never arrive. To tackle this, you have to set up port forwarding. You have to tell the router that a connection on a particular port is to be forwarded to a particular IP address & port (where your server is running) on the local network.

How to configure Port Forwarding?

Different router manufactures have different methods of configuration. The basics shall remain the same however. I have a NETGEAR router, will use it's set up interface for reference. What you need to do first is find the IP address of the router which is normally or If you do not know, open command prompt and type ipconfig on Windows or ifconfig on Linux. The default gateway address is the address of your router. Type this IP address in the address field of your browser and log in to the management panel with the username and password (usually admin & admin). If you do not know the credentials, find out on RouterPasswords. Once you are in the management panel's homepage, look for Port Forwarding/Port Triggering. You may have to look inside advanced settings.

Click on add custom service and give a name to the service, enter the start and end port (if forwarding a single port, start and end port should be the same) to be forwarded and the type of connection (TCP/UDP).

Click apply, return to the port forwarding page and click add.

Select the service you just created, make sure "ALLOW Always" is selected as the action, enter the IP address of your local device and click apply.

Now restart your router and the port forwarding changes shall be in effect.

NOTE: Do not forward all ports. That is, while specifying start and end port, do not specify from 0 to 99999 or something similar. This will choke your router and you will not be able to use the internet connection at all.


Post a Comment