fbpx Dnsmasq | ComputerMinds Skip to main content


24th Apr 2012

Steven Jones

Senior Developer

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:


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: 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.


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


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


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

Then restart Dnsmasq and your networking:

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

And that should be it!


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!