Saturday, 14 April 2012

How to configure a local subdomain development with Linux

Note

In the following scenario everything is done within one machine. This setup can be recreated with more then one machine as well. Use your imagination!

Task

I want to have subdomains like static.mydomain or whatever.mydomain.

Ingredients

any host OS that is capable of running Virtualbox, VMware or your favorite virtualisation software

a linux distribution that uses/supplies a small kernel, like Ubuntu server, Fedora without X, Arch or any of your choice, preferably one that you are familiar with. Of course if you are not a linux guru you can still use a gui, just give enough memory for your guest linux.

Setup process

have your virtualisation software set up on your host

install your linux distro of choice as a guest, it is best to use at least one "Bridged" (my choice) or "Host only" network adapters that every other guest machine can see too if you later need it.

set up your /etc/resolv.conf file to have your nameservers in the following order:
(NOTE: only the first one has to be your localhost, the remaining two is your choice of providers)

dnsmasq configuration

Generally the config file is at /etc/dnsmasq.conf.

Let's say you want to have a domain that is resolved by your machine -who take part in the development- as one of the dev machines address on the local network. For example I want to have the domain ikondev to be resolved to the ip address of VM1 (Virtual Machine 1 on the above image). This way we can have several subdomains for ikondev without updating /etc/hosts file each and every time we add a new subdomain to our webserver to listen to.

In your dnsmasq.conf set the following lines: (these lines has to be uncommented too)

domain-needed

bogus-priv

strict-order (this will make this local DNS server to be the main nameserver)

address=/ikondev/192.168.1.101 (this is the entry for the ikondev domain to point to the machine with 192.168.1.101. You can set up several more entries like this of course)

interface=eth0 (eth0 has to be changed to your network interface which connects to the development network)

no-dhcp-interface=eth0 (eth0 has to be the same as the one for the previous setting as we do not want to set up a dhcp server)

Final touches

Now all we have to do is restart the network and the dnsmasq services and set all the dev machines primary nameserver to be VM2's ip address as it will be serving our local and mainstream resolves.