Archive for November, 2009

A beginners guide to NAT and port forwarding

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.

Setting up Windows XP as a web server

Setting up your own web server is a great way to learn about web hosting and gives you total control over your website and how everything works on it. Whilst Windows XP is not an ideal hosting platform for a very high traffic site, it still has the functionality to allow you to host a decent sized site of your own.

What are the advantages of hosting your own site?

  • 1: Complete control of security, add-ons and logs.
  • 2: You dont have to share your hosting with anyone else.
  • 3: Easy access to files that are stored on your web server.
  • 4: Total control of availability (if you pay for hosting and your site is down then you have to wait for a response from support!)

Like I said before, Windows XP is not an ideal platform for a big size site, and if you really wanted to setup your own web hosting then Id recommend using Windows Server or even Linux, however XP is a great starting point and you can learn a lot from it.

So firstly were going to need web hosting software. In this guide were going to use IIS which comes with Windows XP Pro, there is other software available (the most popular being Apache) but were going to use IIS for this. Lets first check if you have IIS installed, go to control panel > administrative tools, look for Internet Information Services. If you dont have it then go to add remove programs > windows components, choose Internet information services and click details:

install iis

Make sure Internet Information Services Snap-in is ticked, aswell as World Wide Web Service. You can also tick the SMTP and FTP Services but we wont be covering those in this guide. (You may need the windows XP cd for this bit!)

Ok so now that we have IIS installed lets open it up from Admin tools. You should be presented with the following screen:

iis main

By default you will already have a site, unless your going to run multiple sites with different identities then we can use this default site as it is. Right click it and choose rename to give it a more meaningful name. Now we need to start configuring it, the first thing we want to do is choose where our web page(s) are going to be kept. By default Windows will have created a folder on your C drive called inetpub, within that folder you will have one called wwwroot. You can leave this folder as it is or if you want to change where your web files will be served from then right click your website and choose properties, then click the ‘home directory’ tab:

iis home directory

Can you see the local path section in the middle? That is where you choose your directory from. Lets take a quick look at the other settings here. At the top we have 3 radio buttons. If our web files were stored on another machine then we would use the ‘share located on another machine’ option. If we simply wanted to use our site as a redirect to another site then we would use the ‘redirection to url’ option.

Application settings are where to choose our security levels. By default we can leave the application name as it is and this isnt really relevant for IIS in Windows XP. If we were using IIS on Windows Server then we might have application pools for multiple sites but this isnt something we need to worry about right now!

The permissions settings are something we need to be careful with, unless your site has any special requirements we shouldnt need to give write access or directory browsing access, these can pose security risks.

At this point we need to add our content to the site, copy over all your web files to the home directory you selected above. Now we can try to access our site, fire up your web browser and go to the address http://10.10.10.10 (Replace this with your ip address!) or http://your-hostname-here (Again, replace with your hostname!)

Hopefully your web site will be visible! By default your web server will return its default page when a user tries to browse to the root of your website. You can change this setting in the ‘Documents’ tab for your web sites properties and then add/remove items from the ‘Enable Document Default’ section.

At this point your site is live within your local area network (providing your firewall allows it!) For external users to access your site you will need to open up port 80 on your router and point it to your local ip address of your web servers machine. At this point you should set your web server to have a static ip address.

There you have it, a very quick and easy way of setting up your own web server! I havent gone into too much detail here but this guide is enough to get your website live and accesible. In my next guide I will talk about setting up your own domain name (eg www.yoursite.com) and making it point your web server and also some advanced settings in IIS.

An introduction to DNS

DNS (Domain Name System) is the backbone of the internet, you may not know it yet but 99% of what you do online requires and uses DNS. DNS is the internets version of a phone book, but instead of resolving names to phone numbers it resolves names (Domain names) to ip addresses.

What is an IP address? – Well an IP address is a 4 block number (This is for IP Version 4, it wont cover IP version 6 here!) that ranges from 0 to 255. for example: 121.10.45.66 Every  network or machine that uses the internet needs an IP address to communicate with other systems, much like everyone who wants to use a phone needs their own phone number!

Why do we need IP addresses? – Every system or network on the internet needs to be uniquely identified so we can locate it on the Internet. The Internet is not operated centrally, it is a series of networks that are all joined together and identified by their IP addresses.

So what is DNS then? – Well imagine we wanted to access a website, the website is located on a web server that is at the ip address of 55.13.90.88, how would we know this information? Well we wouldnt, it just wouldnt be practical trying to remember a number like this for each website we wanted to visit, that why we use domain names, there much easier for us to remember. All domain names do is make life easier (a lot easier!) for us when were using the internet. So when we are accessing http://www.xyz.com we are actually accessing http://199.26.172.101

How does DNS work? - DNS works on a hierachial structure. When you try to access www.xyz.com your computer does not initially know where the web server is located, so it needs to do a DNS lookup to find out which ip address the server is localted. Your computer will then query its primary DNS server and ask for the answer. Chances are your primary DNS server might be your router. Your router will generally not hold any DNS records and will simply be used a forwarder, it will have its own DNS server configured that it will query (normally your ISP’s DNS server). It will query it and ask it for an answer, there is a chance that your ISP will already have the answer and it will be stored in whats know as the DNS cache, in which case it will return the answer to your router, which will return the answer to you. Your computer now knows the IP address of xyz.com and can start sending data to it.

What if my ISP’s DNS server doesnt know the answer? – If this is the case then the ISP’S DNS server will then query the next server in the chain, this could be a more authorative DNS server that the ISP owns or it could pass the request on to a root DNS server. A root DNS server will always have an answer. If the address has been registered and is globally accessible then the root DNS server WILL have the answer.

What are the root DNS servers? – These are the main DNS servers, they have all the answers and they are queried when a less authorative DNS server doesnt have a record for a domain name. There are 13 DNS root servers around the world and many would consider these to be the backbone of the internet. To put this into context consider this scenario; if all 13 root DNS servers were taken offline then all other DNS servers would eventually expire their cache and empty, if this happened nobody would be able to resolve any external domain names, therefore bringing much of the internet to a standstill.

This is DNS in a nutshell, I have only really scratched the surface here and it is a massive subject indeed but this should provide you with the very basics of what DNS is and how the internet relies on it.