This is a quick tutorial/demonstration on HOW-TO setup a linux server at home. At the end of tutorial, you should expect to have a linux server running apache2, which can be accessed anywhere in the world by type in “http://myfreedomain.redirectme.net” in a web browser.
Keywords: Router, Priviate IP, Dynamic IP, Static IP, Ubuntu Server, Apache Server, Np-IP, Free Home Server
Here is a list of concepts you need to know before reading the rest of this tutorial.
What are private and public IP addresses?
A computer on the Internet is identified by its IP address. In order to avoid address conflicts, IP addresses are publicly registered with the Network Information Centre (NIC). Computers on private TCP/IP LANs however do not need public addresses, since they do not need to be accessed by the public. For this reason, the NIC has reserved certain addresses that will never be registered publicly. These are known as private IP addresses, and are found in the following ranges:
From 10.0.0.0 to 10.255.255.255
From 172.16.0.0 to 172.31.255.255
From 192.168.0.0 to 192.168.255.255
Its basic job is to turn a user-friendly domain name like “coursemate.ca” into an Internet Protocol (IP) address like 220.127.116.11 that computers use to identify each other on the network. It’s like your computer’s GPS for the Internet.
Router Virtual Server:
Ok, let’s get a rough idea how this looks like in a big picture.
So, in this model, you have your local ISP provider, such as Rogers, Bell, or Teksavvy, provides you the internet access with a dynamic public IP (assuming that you are not paying extra to get a static ip, if you are not sure if you have a static ip, just assume that you don’t have one for now). So now, say 18.104.22.168 is your public IP, which can be accessed anywhere in the world to locate your physical. An important note here is that, all the sub-computers under your router have the same Public IP(@22.214.171.124), however, router will assign an unique Private IP to each computer individually (as the 192.168.* shown under each computer)
Also, in this model, you have your PC1(@192.168.0.101), and your Ubuntu Server 10.04 (@192.168.0.100) connect to your router (@192.168.0.1). Your router should have a GUI interface that looks like this:
So now, if someone type in your public IP (@126.96.36.199), the DNS will take them to your router. In such case, they will most likely see the “404 Not Found” page. That’s because for security reasons, your router doesn’t like public access unless you specifically tell it that public accesses are acceptable.
However, that’s not the end of the world, most router today support a feature called “virtual server”, sometimes its also called “port forwarding”. What it does is that it creates a mapping between the router and the computers that connect to it. For example, if you create a virtual server as it’s shown in figure2:
IP Address is the target computer, which is your Ubuntu Server@192.168.0.110 (with Apache2 running)
Public Port is the port that people around the world will use to access your server. In our example, it’s 80.
Private Port is the port that your Ubuntu Server@192.168.0.110 uses for Apache2, by default, it should be 80 as well.
So in general, if someone type in http://188.8.131.52:80/ on a browser’s URL, the DNS will take it to your router, and your router will map the 80 port to @192.168.0.110 at port 80, which is the Apache2 Server on your Ubuntu Server@192.168.110
In short, the setting above will do this for you:
http://public_ip:public_port/ => http://private_ip:private_port/
Congratulations! Now you have a server that anyone in the world can access to. So, what’s next?
If you want to have more convenience access to your Ubuntu Server without type in the tedious IP, instead of a easy-to-remember domain, the following is for you.
All of the issue here is that we don’t have a static public IP. So what can we do about this:
- Contact your ISP see if a static IP is available for you. Usually, this will cost money, but it will save you a lot of troubles.
- Setup a background service that checks your IP periodically, and updates it to a DNS.
And in this tutorial, we will go for the second option, which is to setup this background service.
No-IP is all that we need:
- It checks your Public IP every 5 minutes, and updates it to No-IP’s DNS.
- It provides sub domains to map your Public IP, such as *.redirectme.net subdomains. (I registered turtleland.redirectme.net, and No-IP maps it to my dynamic Public IP, so people can just visit my Apache2 server by turtleland.redirectme.net)
- It’s free. (Well, you could pay to get more features, but the basic feature is more than enough for our task)
Setting this up is very easy. There are instructions available here: http://www.no-ip.com/downloads.php, and I will not repeat them here.
here are some more tips:
- You can buy a domain name like www.yourdomain.com, and redirect www.yourdomain.com to whateverdomainfromNO-IP.redirectme.net. So people can just visit your Apache2 server by www.yourdomain.com
- You can create more virtual servers on your Ubuntu Server, such as mapping port 21(FTP), 22(SSH), and some other application ports you will need.
- You can create a file server on your Ubuntu Server, and serve as a online backup solution for your laptops/mobile device
- You can get a very cheap and dedicated server machine from “IBM Certified Used PC” (Make sure you enter IBMEPP as the promotion code to get the employee discount) http://www-304.ibm.com/shop/americas/content/home/store_IBMPublicCanada/en_CA/icpepcs.html
There are some useful tools to manage your Ubuntu Server. I have the following tools installed:
- webmin: Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more. Webmin removes the need to manually edit Unix configuration files like /etc/passwd, and lets you manage a system from the console or remotely
- Transmission: It’s a torrent client. It has a web interface, so everyone in my house can use it to torrent files. We normally use it to torrent TV shows, Movies, and Music. And the files will be stored in the Ubuntu Server, and everyone in the network can share them. So that we don’t have to download the same TV show multiple times in the same house.
- XBMC. XBMC is a open-source media centre. Since I have a TV connects to my Ubuntu Server, so I can watch movies, TV shows, and even youtube on my TV without paying the TV cable (yes, I am cheap). Setting XBMC on Ubuntu is very straight forward, the instructions are available on its official website, and/or on its community bulletin board.
- Mercurial Server. (Ignore this if you don’t know what it is)