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
sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder;say cache flushed
Further troubleshooting 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