Setting up a TLD for local web development in Ubuntu

Like any good developer, I have a local LAMP server set up so I can develop locally before pushing a site or app to a live production site. This allows me to completely test any modifications to the code base and helps minimize and prevent any possible bugs once the site is live. Once everything is well tested and good to go, I can easily push to production, test again, and be confident everything is working correctly.

My development server is a 64-bit Debian Server running inside a VirtualBox VM on my desktop PC. I run Ubuntu based Linux distributions on all my PC’s, so I could install a LAMP stack on any of them, but I prefer to keep it separated. By using a virtual machine I can more closely emulate the most common server I deploy to, which also minimizes any bugs I might run in to.

So what does all this have to do with setting up a local development top level domain?

Well, my standard process has always been something like this:

  1. Create a directory for project on local server
  2. Set up new virtual host in Apache (usually ‘’)
  3. Update /etc/hosts file to point ‘’ to virtual machine’s ip

That works fine, but I have to add to any computer on the network that I want to be able to access the .dev site. It’s one of those things that I just have been doing for so long that I do it unconsciously. As a developer, I’m always looking for ways to streamline processes and be more efficient.

Enter dnsmasq

What I want is to make the .dev TLD always point to my virtual machine. Wildcards are not supported in your /etc/hosts file on Linux, so we’ll use dnsmasq.

Dnsmasq is a lightweight, easy to configure DNS forwarder and DHCP server.

You can set up dnsmasq on all the local computers on your network to make them all hit your development VM for all request to *.dev.

If dnsmasq is not already installed on your Ubuntu based distro, a simple ‘sudo apt-get install dnsmasq’ will do.

Next, edit /etc/dnsmasq.conf and add this one line:


Where is the ip of your VM. My VM is exposed with a bridged connection to allow it open access to the internet and the local network.

You may need to restart network-manager & dnsmasq:

sudo service network-manager restart
sudo service dnsmasq restart

And you’re good to go. Now you can clean out that /etc/hosts file you’ve been piling domains on.

This is a simple, easy, and somewhat obvious fix, but sometimes you get into a routine and forget to check if your processes can be optimized.