Reputation: 23277
I need to configure a vm into using vagrant and virtualbox as provider. The issue is related to how to allow network comunication between the virtual machine and the host machine.
Concretly, I need:
Any ideas?
Upvotes: 1
Views: 1543
Reputation:
This is how I've set up my VMs lately, hopefully it points you in the right direction.
My requirements were:
To do this use 2 network interfaces on all guests.
Steps:
ip a
and ip r
:config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--nic2", "hostonly"]
vb.customize ["modifyvm", :id, "--hostonlyadapter2", "vboxnet1"] #use proper network name here
vb.customize ["modifyvm", :id, "--cableconnected2", "on"]
end
vagrant up
vagrant ssh
ip a
will show eth1
as downsudo ifup eth1
, in my case this failed/etc/network/interfaces
and add this:allow-hotplug eth1
iface eth1 inet dhcp
sudo ifup eth1
should work now and get an ip from the DHCP of the host-only networkProbably these last steps could be added to vagrant shell provisioning but I'm still new to it.
Edit: add this section to Vagrantfile
for the steps above:
config.vm.provision "shell", inline: <<-SHELL
if ! ifquery eth1 > /dev/null 2>&1; then
sudo echo "allow-hotplug eth1" >> /etc/network/interfaces
sudo echo "iface eth1 inet dhcp" >> /etc/network/interfaces
sudo ifup eth1
ip -4 a show dev eth1
fi
SHELL
ping 8.8.8.8 #web
ping 192.168.178.1 #host
ping 192.168.178.3 #other guest
Hopefully this enables all relevant communication for your use case also.
Upvotes: 3