Better Local Dev Hostnames with Dnsmasq

I use ghost to configure development environment hostnames for all my local test sites. Some DTrace tomfoolery showed me how ghost handles this config: each new hostname is saved to its own plist file.

Update: for zero-configuration wildcard DNS, check out xip.io.

ambackstrom@fsck:~:1$ sudo cat /var/db/dslocal/nodes/Default/hosts/example.com.plist
Password:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>ip_address</key>
    <array>
        <string>127.0.0.1</string>
    </array>
    <key>name</key>
    <array>
        <string>example.com</string>
    </array>
</dict>
</plist>

There's filesystem caching going on behind the scenes and I expect the net impact is negligible, but I wondered if there wasn't a more robust solution that supported wildcards. Having just configured dnsmasq on my router, I started with a brewinstall dnsmasq and was pleasantly surprised to get a progress bar rather than "no available formula." Homebrew recommended a couple post-install actions for setting up a default config file and configuring launchd to keep dnsmasq alive, which I dutifully ran. After that, I enabled my fake TLD in dnsmasq.conf:

# respond to *.zomg with 127.0.0.1
address=/zomg/127.0.0.1

By sheer luck I ended up on this great serverfault.com post explaining Mac OS X's resolver(5) and the /etc/resolver directory. Forcing dnsmasq lookup on my zomg TLD is as easy as:

echo 'nameserver 127.0.0.1' >/etc/resolver/zomg

These settings will work on any network we connect to, no need to modify the DNS servers via System Preferences and put 127.0.0.1 (dnsmasq) in front. Simple, clean, flexible.