How to add a 'Host-only Adapter' to a VirtualBox machine via Vagrant file configuration?

A lot of answers out there are only applicable version 1 of Vagrant file configuration. e.g.

config.vm.network :hostonly, :adapter => 2

The new public network does not support this feature. e.g. this line here

config.vm.network "public_network", bridge: 'vboxnet0'

Will throw an error because vboxnet0 is not a network interface like en0. Here is a screen shot:

enter image description here

I have also tried

config.vm.provider "virtualbox" do |vb|
  vb.customize ["modifyvm", :id, "--hostonlyadapter2", "vboxnet0"] 

But it has no effect on the virtual machine.

How can I create a new interface like this?

enter image description here

I am using

  • Mac OS X 10.10.1
  • VirtualBox 4.3.20
  • Vagrant 1.6.5

Solution 1:

I think I have found an answer.

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

This will create a host-only adapter as I wanted in my question

Solution 2:

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.