Dnsmasq (no editing /etc/hosts)

I’ve played around bit recently with Pow (http://pow.cx/) on Mac OS for running Ruby development sites. One of the nice things it does is automatically handle resolving requests to the dev site. For example, requests to http://mysite.dev/ will automatically be handled by the localhost, so there is no need to add a line like

127.0.0.1  mysite.dev

to the /etc/hosts file.

I’m using Ubuntu linux now and have discovered Dnsmasq, which is a lightweight DNS server, useful for serving DNS entries that are not in the global DNS. You can set it up to match anything ending in .dev to resolve to the localhost (127.0.0.1). So, I’ve created a file called /etc/dnsmasq.d/dev.conf containing the following

address=/dev/127.0.0.1

Now, after restarting Dnsmasq (sudo service dnsmasq restart), all requests to .dev return the localhost IP.

I typically create new files in the .d directories for alterations to config files, instead of editing /etc/dnsmasq.conf  directly, as helps to avoid conflicts when upgrading the packages.

If you enjoyed this post, consider leaving a comment or subscribing to the RSS feed.
This site uses cookies. Find out more about cookies.