If Vagrant is not reachable after disconnecting from a VPN, first run these commands to bring the interface down, then back up:
sudo ifconfig vboxnet0 down sudo ifconfig vboxnet0 up
For a long term solution, consider adding the code below to the Vagrantfile, which will use the host as DNS:
config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] end
Flush all local DNS caches for OS X 10.10.4+ by running:
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say cache flushed
Further troubleshooting steps
- Make sure you’re disconnected from the VPN.
- Making sure no VMs are running.
- Reboot your computer.
- Start the virtual machine form the VirtualBox GUI, and enter
vagrantfor the username and password.
- Power off the machine from the VirtualBox GUI (if it’s in a corrupted state, starting from VB and powering it down from VirtualBox will help resolve a lot of potential issues).
- Attempt to
- If it still doesn’t work after these steps, you might need to destroy and re-provision your vagrant box. If you use Varying Vagrant Vagrants (VVV), you can run vagrant destroy, then follow these steps.
To prevent recurrence
- Use OpenConnect instead of Cisco’s AnyConnect for your VPN client. Folks in my circles say it’s better in general and less prone to cause issues like this.
- Shut down vagrant VMs before you connect to a VPN, and before you disconnect.
Source for the first few commands listed above: http://stackoverflow.com/questions/20339191/vagrant-with-vpn-connection-over-host-computer
Written by Kellen Mace, who lives in Rochester Hills, MI and builds cool stuff on the web. About Kellen // Follow him on Twitter →