If you’re a developer who frequently updates his hostfile to try out new sites or services locally, you might want to try dnsmasq.

I’m running OS X Mountain Lion. All development takes place in a couple of Vagrant-managed Virtualboxes running on 33.33.33.x.

I don’t like having to wait for sysadmins to get DNS stuff and its paperwork in place, so I just configure some rules in dnsmasq and point these domains to my virtual server.

To get started:

  • Install Homebrew (instructions found over there)

  • Install dnsmasq

$ brew install dnsmasq
  • Copy the plist file over:
$ sudo cp /usr/local/Cellar/dnsmasq/2.61/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons/
  • Copy the example config over:
$ cp /usr/local/Cellar/dnsmasq/2.61/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
  • Add as the first entry in OS X > System Preferences > Your connection > Advanced > DNS

  • Edit /usr/local/etc/dnsmasq.conf, adding some address= entries as you please:

# This entry redirects every domain ending in .dev to the Vagrant box on
  • Launch the dnsmasq daemon:
$ sudo launchctl start homebrew.mxcl.dnsmasq
  • Flush your dns:
$ sudo dscacheutil -flushcache
  • Test if it worked:
$ dig www.someproject.dev
  • Should answer with:
www.someproject.dev.		0	IN	A

I’m also considering setting up an SSH tunnel from my VPS to my Laptop, like showoff.io, but DIY.