Thursday, May 12, 2016

Sharing host VPN with Vagrant - Rob Allen





Computing

When moving a project into Vagrant, I realized that I needed the vagrant guest to share my OS X's VPN.


I'm using a separate IP address within a private network like this:
config.vm.network :private_network, ip: "192.168.101.101"
So, after some Googling, I added this provider configuration setting:
  config.vm.provider :virtualbox do |vb|
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end
and now my VM is sending data over the VPN. Note that this will not work when using the Vagrant's public_network setting though.

PuPHPet

These settings are the default for puphpet, BUT if you setup a public_network interface it will not work.

Resources
https://akrabat.com/sharing-host-vpn-with-vagrant/ -- quoted here.
http://renier.morales-rodriguez.net/post/90674523562/sharing-host-vpn-with-virtualbox-guest

Here is an example of how to add public_network only when you need it... 
➜ IP='public' vagrant status
added to Vagrantfile

Vagrant.configure("2") do |config|
  ...

  # IP='public' vagrant status
  if ENV['IP'] == "public"
      # https://akrabat.com/sharing-host-vpn-with-vagrant/
      puts("[info] PUBLIC interface added")
      config.vm.network "public_network", :mac => "4CA3AB1EBBB1"
  end
end
:)