When working with various virtual machines and browsers, your hosts file can start to look a little over subscribed, and rather difficult to manage.

One of my colleagues mentioned dnsmasq – and he implemented it on his host machine to resolve names for various VM’s.

I didn’t really want to install it on the host, so went for having it on the VM, so that each one could resolve it’s own list of domains. In the instructions, I’m making the assumption that the VM has a DHCP provided IP from the host only network within VirtualBox, and it’s host name (the name I’m connecting to from the host machine is devbox). Here’s what I did.

1. Install dnsmasq on Debian with apt

sudo apt-get install dnsmasq

2. Open up /ect/dnsmasq.conf and add:

address=/devbox/192.168.56.101

3. Restart dnsmasq

sudo /etc/init.d/dnsmasq restart

4. Then in your host machine’s /etc/hosts file add:

devbox 192.168.56.101

5. If you’re using OS X, create the folder /etc/resolver

sudo mkdir /etc/resolver

6. Create a named entry for your box

Mine’s called devbox, I’d do:

echo "nameserver 192.168.56.101" > /etc/resolver/devbox

And that should now work nicely – somesubdomain.devbox for example will  resolve to that VM.

 

2 Responses to Using dnsmasq with VirtualBox and OS X

  1. Ben says:

    I recently had to do the same thing for OS X Lion given its new, stupid, DNS resolution order:

    http://www.justincarmony.com/blog/2011/07/27/mac-os-x-lion-etc-hosts-bugs-and-dns-resolution/

  2. Tim says:

    Thanks for the link and comment Ben!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="">

Set your Twitter account name in your settings to use the TwitterBar Section.