Friday, July 18, 2008

Port Forwarding A Guide

Writen by Ajay Divakaran

So first, here are a couple of things that you can do after you finish this section.

- You can configure BitTorrent to give you excellent speeds

- You can configure your computer to play multiplayer games over the internet

- You can setup your computer as a terminal server (for remote desktop connections)

- and many many more cool stuff!!

This tutorial consists of 2 sections

1. Understanding Port Forwarding

2. Implementing Port Forwarding on common routers

What is portforwarding?

In one sentence, portforwarding makes the internet see your computer as if it were directly connected rather than being connected though a router. For the same reason, if you dont have a router, and your computer IS directly connected to the Internet, then you wont need this tutorial.

A little explanation: When a computer is connected to the internet, it is assigned a unique address called the IP address. This enables other computers on the internet to communicate with it and send packets to it and so on... An IP address has the format ###.###.###.###. It looks like four sets of numbers, separated by a dot. Each set can have a value between 0 and 255.

Usually the internet service provider is the guy who assigns you an IP address for your connection. However, he gives you only ONE ip address and this gets assigned to the cable/dsl modem at your house. If you directly connect your computer to the cable/dsl modem, you are using this IP address to communicate with other computers on the internet. However, you can connect only one computer to the cable modem at any given time. So you go to the nearest store and buy a router.

Role of the router

A router connects to the cable/dsl modem and splits the one internet connection into multiple connections so all the computers in your house can enjoy internet connectivity simultaneously. Once you get the router, you connect the router to your cable/dsl modem, and all your computers to the router.

Internal and External IP addresses

Once you start using a router, the IP address given by your internet service provider gets assigned to the router. This IP address is called the External IP address, as it is part of the external network between your router and the Internet. The router in turn assigns new IP addresses to the computers connected to it. These addresses are a part of your Internal Network, and are called Internal IP addresses. By set laws, an Internal IP address may start with the numbers 10,128, or 192. All the other combinations are used for external addressing.

For example, my external IP address is 68.36.145.156. This IP address is assigned to my router. I have two computers connected to the router, and they have the IP addresses 192.168.0.10 and 192.168.0.11. These are my internal addresses.

The Port concept

Even when you use a router to connect many machines to the internet, other computers on the internet see one single machine with the external IP address of the router. They dont know that a router is sitting inside your house and splitting the external address into many internal IP addresses. They can only make a connection to your router, and your router decides how to route the connection and to which internal computer to route it to.

IP addresses are further divided into channels called ports. This permits one IP address to be shared by multiple programs at the same time, each using a different port. By standard every computer has 65536 ports (numbered 0 to 65535). When a computer attempts to talk to another computer, the attempt is always initiated along with a port number.

Forwarding Ports

Lets assume that a computer on the Internet needs to initiate a connection to a specific software on your computer. The software in discussion uses port 12345. For simplicity, we will call the initiating computer as ClientX, and your computer as the ServerX. As we discussed earlier, clientX only sees (and knows) the external IP address i.e. the IP address of your router. It tries to initiate a connection to that IP address with the port number 12345. However, your router recieves this request, and sees 4 computers in your house connected to the router. The router is not able to figure which computer the connection from ClientX was intended for! So it simply drops the connection.

Port forwarding is a setting in the router which you can change to prevent this from happening. By doing this, you can tell the router that any connections for port 12345 has to be forwarded to ServerX. Now when the router recieves a request for a connection on port 12345, it checks its table and sees your entry saying that all connections for port12345 have to be forwarded to serverX. Hence it routes the connection accordingly!

Here we'll see how to do portforwarding on most routers.

Scenario : Lets say you need to forward port 6889 to a computer whose Internal IP is 192.168.1.10.

Step 1: Find your gateway IP address. To get this, in windows, select Start > Run. Type in "CMD" and hit enter. Inside the command window, type "ipconfig" and hit enter. The screen will show you the default gateway. Note this down.

Step 2: Open Internet explorer. Enter your gateway from Step 1 in the address bar, and hit enter. A popup window will ask you to authenticate into your router with a username and password. Enter the username and password. If you dont remember, try the default ones below:

Linksys router : Default username "" password "admin"
NetGear router : Default username "admin" password"password"
Belkin router : Default username "" password""
D-Link router : Default username "admin" password""
Gateway router : Default username "admin" password"admin"
If you cant remember the password, post it on the forum at forum.techorient.com and someone will help you!

Step 3:

For Belkin routers, select virtual servers from the left menu. Enter something for description. Type "6889" or the required port number in both fields for inbound port. Do the same for the Private port fields too. Select the connection type from the drop down. If you dont know what you need, try UDP. If that doesnt work, come back and try TCP. In the private IP address field, enter the computer to which you need the connection forwarded. In our case, this is 192.168.1.10

Linksys routers, select "Application and Gaming" from the top menu, and the select 'portrange forwarding' from the submenu. In another family of linksys routers, you can find 'Forwarding' section under 'advanced' tab of main setup page. Rest of the process is the same as that for Belkin routers above.

Netgear routers, you'll find 'Port Forwarding' under the 'Advanced' table in the main page. The rest of the steps are same as above.

Step 4:

Save the setting and restart the router. Your port forwarding is complete.

No comments: