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

1. Make sure you’re disconnected from the VPN
2. Making sure no VMs are running
3. Reboot your computer
4. Start the virtual machine form the VirtualBox GUI, and enter vagrant / vagrant for the username and password
5. 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)
6. Attempt to ‘vagrant up’
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

2 comments

  1. Best VPN For Chromebook January 17, 2017 at 9:16 pm

    Reply

    Thanks for posting this awesome article. I’m a long time reader but I’ve never been compelled to leave
    a comment. I registered your blog in my rss feed and shared it on my Facebook.
    Thanks again for this great article!

  2. devops online training January 26, 2017 at 5:40 am

    Reply

    Oh my goodness! Incredible article dude! Many thanks. 

Leave a reply

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