Local Wildcard Domains on OS X

fgnass 26 February 2013

This post shows how to map *.dev domains to localhost and make them accessible from within VirtualBox.

Adding an IP alias

By default VirtualBox maps the IP to the host’s loopback interface. So instead of mapping *.devdomains to as one would normally do we let them resolve to and set up an IP-Alias for the loopback interface. In order to permanently add the alias we have to put this plist file into the /Library/LaunchDaemons/:

# Download the gist
sudo curl https://gist.github.com/fgnass/5037138/raw/676369616ee8ba5f8c77a9b32d2a60ecd05edaf0/ipalias.plist -o /Library/LaunchDaemons/ipalias.plist

# Let launchd execute the command
sudo launchctl load /Library/LaunchDaemons/ipalias.plist

To verify that the command was executed successfully run sudo ifconfig lo0 | grep which should display the following output:

inet netmask 0xff000000

Installing a DNS forwarder

To actually resolve the *.dev domains we install dnsmasq a lightweight DNS forwarder:

# Install dnsmasq via homebrew
brew install dnsmasq

# Resolve *.dev domains to
echo "address=/.dev/" > `brew --prefix`/etc/dnsmasq.conf

# Launch on Startup
sudo cp `brew --prefix dnsmasq`/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

# Use dnsmasq as nameserver
sudo bash -c 'mkdir /etc/resolver && echo "nameserver" > /etc/resolver/dev'

You should now be able to ping foo.dev as well as any other .dev domain.

Setting up the nameserver in your Virtual Machines

The last step is to tell your VMs to use as DNS-Server. Under Windows this looks like this:


If you spot an error please create an issue or drop me a line on twitter.