Vagrant + VirtualBox + VPN == DNS FAIL

I have been using Vagrant to manage development VMs for a few weeks now. It works great. However a recent change to my VPN client configuration caused me problems.

I selected the VPN client option to use a remote DNS server. This allows me to access remote hosts by name instead of by IP address or using an /etc/hosts file. It is convenient, but totally broke DNS resolution in my guest VMs.

I did not try to figure out the root cause, but whenever I am connected to the VPN, the guest cannot resolve any hosts. My guests use NAT networking in VirtualBox. The DHCP client on the guest is configuring /etc/resolv.conf with the IP address of my host machine’s interface on the NAT network.

The quick fix was to add PEERDNS=”no” to the guest OS /etc/sysconfig/network-scripts/ifcfg-eth0 file (the guest OS being CentOS). And then hard-coding the DNS server address to something like 8.8.8.8 in /etc/resolv.conf, which if connected to the Internet should always work. I made this change in the VM that I created my basebox from, repackaged it and now any Vagrant VMs derived from it have this change. At least Vagrant made it easy to propagate the change to the other VMs.

I am sure there is a bug somewhere in the DNS resolver or proxy that VirtualBox ships with that is the root cause, but I have been too busy to spend any time digging further.


About this entry