There are scenarios where you only have one public ip address but want to host many domains, each on their own dedicated virtual or physical server.  For instance you may want to host several different WordPress sites from your home using several old computers from circa 1998 you found in a closet sitting ontop of a stack of Zip drives, and your trusty.. OK, well.. semi-trusty home internet connection.   I did some online digging and was shocked to find that most people, even many experts claim that this is not possible.  This is absolutely possible!  I will show you how!  First, before we begin, the regular old disclaimer applies here.  I’m not claiming this is the only, best, or even correct way to do this.  I’m simply explaining the steps I took, and what worked for me.  I am not responsible if mid way through, your internet connection zaps you and you wake up back in 1992… OK well with that out of the way.. lets get to the FUN!

First a diagram!

Above on the left is a typical home network.  You have the Internet connected router that you most likely received from your ISP.  Connected to that router you have all of the devices that make up your home network (not shown) like laptops, pc’s printers, mobile devices etc.

What we are going to do is set up a linux machine running Ubuntu server 14.04 with two network cards in it.  We will then install and configure Pound proxy on this machine (middle of diagram).  We will connect the first network card on the machine, labeled “eth0” to the existing home network and assign it a static local ip.  The second network card will connect to each of our web servers either through a physical or virtual layer 2 switch.  The Ubuntu machine running Pound proxy, (just Pound proxy from now on) and the web servers can be physical or virtual machines and the setup process for each are almost identical, except for when we get to the layer 2 switch between the Pound proxy and the web servers.  I will walk through the configuration steps for setting up physical machines, and also virtual machines running on Citrix Xenserver.

The machine to use as the Pound proxy does not need much power at all. You can get away with 512mb ram, 8gb hard drive, however you do need two network cards installed in the machine.  Also connect one of the network cards, preferably the one that the system will recognize as the first network card or “eth0” to your existing home router before you proceed.

The first step is to install Ubuntu Server 14.04 on said machine, you can grab an ISO here.  Simply burn the iso to a disc, place in machine and boot from the disc (if a physical server) or boot your virtual machine from the iso file. I’m not going to go into the details of the install because it is pretty straight forward, like installing any other OS.  There are also many good guides on installing Ubuntu online as well.  A couple of key points are: When the system detects the network devices, it will assign names “eth0” & “eth1” to them, make sure that you plugged the network cable from your router into “eth0” and not “eth1”, if you did plug it into the wrong port, then Ubuntu will fail to set up dhcp on interface eth0. This is no problem, just plug the cable into the other nic and then tab to “try again” and hit enter.

Ubuntu NIC Screenshot

Ubuntu NIC Screenshot

When you get to the part of the installation that asks you to choose what software to install on the server make sure only “ssh” is checked, as that is all that we will need.

20140825-114727.jpg

When installation is done and machine is rebooted, we will boot into the terminal of a fresh Ubuntu Server 14.04.

Login using the username & password created during the install.

Commands to type are in white boxes below and can be easily copied and pasted.

Once logged in lets turn into the root user with the following command.

sudo su
You will be prompted to enter you password.

At this point we need to hard code a ip address outside of the home routers dhcp range. So if your home router distributes ip’s from a range between 192.168.1.100 and 192.168.1.200 (you will have to log in and check), you will want to hard code a ip address outside of that range. For my machine I am going to use 192.168.1.20. I am also going to configure my router to forward TCP port 80 to 192.168.1.20, this way all http requests will go directly to the Pound proxy.

Using the nano text editor lets open the network configuration file and configure a static or hard coded ip for both interfaces.

nano /etc/network/interfaces
Modify the section:

 # The primary network interfaceauto eth0iface eth0 inet dhcp 

to look like this:

# The primary network interfaceauto eth0iface eth0 inet staticaddress 192.168.1.20netmask 255.255.255.0gateway 192.168.1.1broadcast 192.168.1.255dns-nameserver 8.8.8.8 8.8.4.4# Pound Back-end Networkauto eth1iface eth1 inet staticaddress 10.0.0.1netmask 255.255.255.0broadcast 10.0.0.255 
Press <CTRL> + X

Then “Y” and “enter” to save the file.

both interfaces are now configured. Now lets activate the second interface that we will connect to the Layer 2 switch and to the Web servers.

ifup eth1
Lets update the os.
apt-get update && apt-get upgrade -y
Install Pound.
apt-get install pound
Now, if your on a physical machine at this point you are going to need to plug your second nic into a layer 2 switch. If you do not have one laying around just google "network switch" and any will do, chances are your home internet upload speed are very slow, so spending more than $10 - $15 here for something over 100mb/s is going to be a waste. Unless you are not doing this at home or have a nice upload bandwidth, then by all means, chose what fits you best.  Also you are going to need as many ports as you have web servers. So if you plan on running 15 Web Servers you will need a 16 port switch (one for each web server and one for the proxy).

Next lets configure Pound.

Lets say we have two web servers connected to the switch.

webserver 1 will host abc.com and its ip address is 10.0.0.2

Webserver 2 will host 123.com and its ip address is 10.0.0.3

We now want to configure pound so that it listens on eth0, 192.168.1.20 port 80 for incoming http requests.

Once it receives these requests we want pound to look at the url and filter it so that all requests for abc.com are sent to 10.0.0.2

and all requests for 123.com are sent to 10.0.0.3

To do this we edit the following file like so:

nano /etc/pound/pound.cfg
edit below the section that starts with:

"## listen, redirect and ... to:"  to look like this:

ListenHTTP Address 192.168.1.20 Port    80 ## allow PUT and DELETE also (by default only GET, POST and HEAD)?: xHTTP1 Service HeadRequire "Host: .*abc.com.*" BackEnd  Address 10.0.0.2 Port    80 End End Service HeadRequire "Host: .*123.com.*" BackEnd Address 10.0.0.3 Port 80 End EndEnd 

You would repeat this pattern for every server. The only difference is that the final line has one more "End" at the end.

So if you had 100 web server there would be a url pattern and ip address for each host.

thats it!

Now restart the pound service for the configuration to take effect.

service pound restart
You should now navigate to the url abc.com and the request will be served by the webserver at 10.0.0.2 and you will see the content on that web server.

Likewise, if you navigate to 123.com the request will be server by the host at 10.0.0.3

*Note

Configure your domain names that you own, to point to you public ip address. This usually involves logging into your account with whomever you bought the domain names from and just configure the dns A file to point to you public ip address.

Next I will go over this same setup in a Citrix Xenserver environment with virtual networking.

Also, I will go over standing up a new apache2 web server and lamp stack.

Aliens? Any thoughts?

This site uses Akismet to reduce spam. Learn how your comment data is processed.