Jordi
Jordi

Reputation: 23187

Vagrant: Configure two NICs on guest (Host-Only adapter and NAT) on virtualbox

I need to create a vm using vagrant with two network interface cards on virtualbox. I've configured them manually, but from now on, I need they are provided by vagrant.

So I need:

  1. A Host-Only Adapter on 192.168.56.* with DHCP enabled.
  2. A NAT adapter in order to be able guest get access beyond host.

Any ideas?

Currently, my host-only network adapters are:

enter image description here

Upvotes: 1

Views: 10243

Answers (3)

JPaulino
JPaulino

Reputation: 3477

In my case, I did the following: 1) Enabled a new 'host-only' adapter in virtualbox: just select your box, click 'settings', click 'network' and enable a different adapter than your other boxes have.

2) Check the ip of that adapter you created by running 'ipconfig' in powershell or command line in Windows.

3) Finally, in your vagrant configuration file, specify an ip within the adapter's network: config.vm.network "private_network", ip: "place_ip_here".

If your adapter's ipv4 is '172.28.128.1', for example, and subnet mask '255.255.255.0', then your first three numbers in the IP remain the same '172.28.128.another_number_here'

Upvotes: 1

san1512
san1512

Reputation: 1023

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/xenial64"
  config.vm.network "private_network", type: "dhcp"
end

Works for me, though I already had 'vboxnet0' configured by default, it created a new host-only network 'vboxnet1'.

I was not able to use vboxnet0 further it throws conflicting network error. Creating multiple vms with above config worked for me using vboxnet1 by default.

Upvotes: 0

Frederic Henri
Frederic Henri

Reputation: 53703

vagrant will always configure a NAT (1st interface) so vagrant can communicate on ssh from host to VM (you can read https://stackoverflow.com/a/35211086/4296747 for more info)

After if you want to enable another network interface, vagrant will support the creation of an interface (check vagrant network doc) and if you specify the interface, something likes this should work

config.vm.provider "virtualbox" do |vb|
    config.vm.network "private_network", :type => 'dhcp', :name => 'vboxnet0', :adapter => 2
end

Upvotes: 2

Related Questions