Im sure a lot of you have heard of port forwarding, most of you will have heard about it when you were trying to find out how to get your torrents to download faster! Well in this article im going to go through the basics of port forwarding, why we need to do it and how its done.
To understand port forwarding you need to understand how the internet works, specifically ip addresses (public and private) and ports. Lets start with ip addresses.
Public and Private ip addresses – When the internet was first created and an ip addressing scheme was introduced the designers never envisioned that in 20 years time we will have ran out of the 4.3 billion addresses (approx). Well this is exactly what is happening now, and if it wasnt for the development of NAT (Network Address Translation) and port forwarding then there is no doubt we would have completely ran out of address space by now. Every device that communicates over the internet has to use a public ip address, but with limited address space available then many devices will share the same public address, this is called NAT.
Note: IPV6 is the new version of IP that will ridding us of NAT and enabling us to have true end-to-end connections on the internet again.
So this is where private ip addresses come in. Every device that shares a public ip address still needs its own individual ip address within its local network, there are three reserve address pools that are not routable on the internet and are used to assign to devices behind a NAT router. To put this into practice lets consider an example. You have broadband at home and yourself, your mom and your sister all have their own laptops. Lets take a scenario where your all browsing the internet at the same time, well your all using the same public IP Address but your using different private ip addresses, for example; 192.168.1.1 192.168.1.2 192.168.1.3.
Ports – All communication on the internet is sent via different ports, this ensures that traffic is sent to the right application, for example you have a different port for browing the web and checking your email (providing your not using webmail!)
The problems of NAT – Whilst NAT has no doubt ‘saved’ the internet from address space exhaustion it has caused a few problems, when using NAT we are essentially stopping the end-to-end connection design that the internet was built upon. This means that not every device has its own unique identity on the internet. It also means that routers have had to add a whole new level of calculation to determine where to send traffic from a public ip to a private one, not only this but some older software is not NAT compatible and wont work correctly on the internet now.
PAT (Port address translation) – There are 3 different types of NAT but the most common and the one were going to talk about here is PAT. Essentially your NAT capable router holds a table of translations and their relevant ports. Lets say you have two computers on the same local network both sending a request to a different web page at the same time, when both web sites send their response back to your router, how does your router know which page to send to which computer? Well when it receives a request from an internal machine it keeps a record of the internal ip address and assigns it an available source port. When it receives a packet back from the web server it analyses the destination port and matches it up with its own table, it then knows which local machine to send the data back to!
Port Forwarding – Port forwarding works on a very similar principle although it is technically the othe way round. Lets say you are hosting a website or a server of some kind at home. You have given your friend your public ip address to connect to it, when he does so your router receives a packet destined for port 80 (HTTP) how does your router know where to send this to? Well this is what your port forwarding table is for, in this instance you would create an entry to send all incoming port 80 traffic to a local ip address on your network. Of course this means that only one device can use that port per public ip address.
So esentially if you want to host a site or a server of any kind then you need to setup port forwarding, basically anything that requires a remote host to establish a connection with you it must be port forwarded, a good example of this would be torrent traffic and its probably the most commonly used port forwarding for home users!
Well thats it for now, you’ve just learn the basics of port forwarding! Feel free to leave a comment.
