Author image
Senior Developer

Dnsmasq

When developing we tend to use a lot of different domains to do our work on, I typically will use the .drupal top level domain, so my project URLs look something like:

project-name.drupal

When starting a new project, one of the annoying things that we have to do is create an entry in the hosts file for this domain:

127.0.0.1      project-name.drupal

On Ubuntu there is a really simple way to automate this and give yourself a 'wilcard' DNS entry, so any domain that ends in .drupal will resolve to my local machine. Enter Dnsmasq.

Installation

This should work for 10.04 and above, but your millage may vary.

Install the 'dnsmasq' package:

apt-get install dnsmasq

Dnsmasq is a leightweight DNS server, so is capable of doing lots of things, but today we're just going to set up our .drupal top level domain.

Edit /etc/dnsmasq.conf and add a line to the bottom

address=/.drupal/127.0.0.1

And ensure that somewhere in the file there is the following line, adding it if it's not there:

listen-address=127.0.0.1

Now we need to get our DNS server being used, there are many ways to do this, and it can depend greatly on your networking setup, but in most situations you'll be connected to some external network, obtaining your IP address via DHCP. In this situation the easiest way to add Dnsmasq to your DNS servers is to edit /etc/dhcp/dhclient.conf and add or uncomment the line:

prepend domain-name-servers 127.0.0.1

Then restart Dnsmasq and your networking:

/etc/init.d/dnsmasq restart
/etc/init.d/networking restart

And that should be it!

Troubleshooting

Okay, so DNS is really hard to get set up sometimes, and you can very easily end up in a situation where you can't access the internet, if you find yourself in this situation, just un-do what you have done, and restart your machine.

Networking is a complex beast, and is subtly different all the time, so these instructions may not work in your case, sorry!

More automation

So when starting a new project I still have to create Virtual host files for sites in Apache, but you can get Aegir to do that for you too!