what vagrant or box config controls vboxnetX creation?

528 views
Skip to first unread message

ben sholdice

unread,
Mar 8, 2017, 6:29:16 PM3/8/17
to Vagrant
macbook pro with Vagrant and Virtualbox. I'm trying to add an interface to my VM that is on a Virtualbox hostonly network that uses DHCP but I when I add a private_network in my Vagrantfile I see that vagrant has created a new hostonlyif vboxnet1 with a new DHCPServer. What configfiles control this? how do I force the new private interface to be bound to my existing vboxnet0?


VBoxManage output when Vagrantfile does not contain a config.vm.network line:
macbook:  VBoxManage list hostonlyifs
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
DHCP:            Disabled
IPAddress:       192.168.10.1
NetworkMask:     255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0

macbook:  VBoxManage list dhcpservers
NetworkName:    HostInterfaceNetworking-vboxnet0
IP:             192.168.10.1
NetworkMask:    255.255.255.0
lowerIPAddress: 192.168.10.10
upperIPAddress: 192.168.10.99
Enabled:        Yes

NetworkName:    NatNetwork
IP:             10.0.2.3
NetworkMask:    255.255.255.0
lowerIPAddress: 10.0.2.4
upperIPAddress: 10.0.2.254
Enabled:        Yes


add the 'vm.network' line into my Vagrantfile and I see the following outputs:

MacBook:  VBoxManage list hostonlyifs
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
DHCP:            Disabled
IPAddress:       192.168.10.1
NetworkMask:     255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0

Name:            vboxnet1
GUID:            786f6276-656e-4174-8000-0a0027000001
DHCP:            Disabled
IPAddress:       172.28.128.1
NetworkMask:     255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:01
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet1

macbook:  VBoxManage list dhcpservers
NetworkName:    HostInterfaceNetworking-vboxnet0
IP:             192.168.10.1
NetworkMask:    255.255.255.0
lowerIPAddress: 192.168.10.10
upperIPAddress: 192.168.10.99
Enabled:        Yes

NetworkName:    NatNetwork
IP:             10.0.2.3
NetworkMask:    255.255.255.0
lowerIPAddress: 10.0.2.4
upperIPAddress: 10.0.2.254
Enabled:        Yes

NetworkName:    HostInterfaceNetworking-vboxnet1
IP:             172.28.128.2
NetworkMask:    255.255.255.0
lowerIPAddress: 172.28.128.3
upperIPAddress: 172.28.128.254
Enabled:        Yes


here are my versions:
macOS 10.12.3
Vagrant 1.9.2
Virtualbox 5.1.14 r112924 (Qt5.6.2)

and heres my Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
  config.vm.box = "geerlingguy/ubuntu1604"
  config.vm.hostname = "ubuntu"
  config.vm.network "private_network", type: "dhcp"
end


Thanks in advance,
Ben

Alvaro Miranda Aguilera

unread,
Mar 9, 2017, 5:31:00 AM3/9/17
to vagra...@googlegroups.com

Hi

try:


# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
  config.vm.box = "geerlingguy/ubuntu1604"
  config.vm.hostname = "ubuntu"
  config.vm.network "private_network", type: "dhcp", name: "vboxnet0"
end






--
Alvaro


Virusvrij. www.avast.com

ben sholdice

unread,
Mar 9, 2017, 12:17:26 PM3/9/17
to Vagrant
oh that sounds perfect. Where can I find the complete syntax options for my Vagrantfile?

Also, I would still very much like to learn how vagrant controls/interacts with Virtualbox. When I start my MV using the GUI I don't see vboxnet1 & its dhcpservjer get created, so I can only assume that vagrant is instructing Virtualbox to do this.

Thanks for your reply Alvaro!

Ben    

ben sholdice

unread,
Mar 9, 2017, 2:39:13 PM3/9/17
to Vagrant
well now I'm caught up in what seems like common issue - 'vagrant up' errors out with a conflicting dhcpserver configuration:

ERROR warden: Error occurred: A host only network interface you're attempting to configure via DHCP
already has a conflicting host only adapter with DHCP enabled. The
DHCP on this adapter is incompatible with the DHCP settings. Two
host only network interfaces are not allowed to overlap, and each
host only network interface can have only one DHCP server. Please
reconfigure your host only network or remove the virtual machine
using the other host only network.

From my searches it seems several bug reports advise manually removing the dhcpserver running on vboxnet0:

"VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0"

and when I do this I see that 'vagrant up' completes without error the first time, but apparently it recreates vboxnet0 and adds a dhcpserver (using ip addresses and dhcp ranges I did not specify. Then every attempt to 'vagrant up' after this ends in the same "A host only network interface you're attempting to configure via DHCP..." error.

I really need to know how & where vagrant is configuring these hostonlyifs and dhcpservers. surely this is documented somewhere??

Ben 

Alvaro Miranda Aguilera

unread,
Mar 10, 2017, 7:25:04 AM3/10/17
to vagra...@googlegroups.com
Hello Ben

First and foremost, welcome to the mailing list. feel free to send all the questions you have, don't be shy, some questions may be already answered on the documentation, so we can help point where that is.

other questions may be real issues that can be tracked, may be new, etc. so have patience and enjoy the ride.

So, starting point in the documentation is here:

Them you will see the options on the left. They are grouped since Vagrant does the abstraction. ie, adding a new network in Virtualbox and VMWare is the same.

To reply your questions.

Vagrant interact with VBoxManage, so all what vagrant does, is a combinations of commands using VBoxManage.

You can learn more about VBoxManage on the documentation:


So for your questions.

Vagrant try to do things on your behalf, some are nice and clean and work, other may be still some edge cases that need polish. Whats the best way to deal with those?

- Get something that can be reproduced, if you can reproduced with the lastest version of Vagrant and Virtualbox, then will be easier to reproduce so developers can have a look.
- If you think you have found a bug, you can open a issue on GitHub, the more information and repro case the better. Host OS, versions, guest os, happen on other guest os? you can open issues here: https://github.com/mitchellh/vagrant/issues

So, in your use case here.


Lets say you want to have a VM in Vagrant and you want use whatever network is defined,and get dhcp.

In Vagrant looks like this:

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


So, you need to make sure the network have dhcp enabled and its created.

You can have something like this by default:

Inline image 1

So once the VM got created, we can inspect the VM and see where it got connected:

$ ./VBoxManage.exe list vms
"p64_default_1489148194517_15337" {ff9bb485-84a2-4896-9d9f-cf8ac39d869a}

$ ./VBoxManage.exe  showvminfo ff9bb485-84a2-4896-9d9f-cf8ac39d869a | grep -i Ether
NIC 2:           MAC: 080027D071C2, Attachment: Host-only Interface 'VirtualBox Host-Only Ethernet Adapter #2', Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none

Vagrant created this network.



And we can check the IP on the guest:

$ vagrant ssh -c 'ifconfig eth1'
eth1      Link encap:Ethernet  HWaddr 08:00:27:d0:71:c2
          inet addr:172.28.128.3  Bcast:172.28.128.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fed0:71c2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:4006 (4.0 KB)  TX bytes:1152 (1.1 KB)


Vagrant created a VM, eth1 private, and assigned it to the 'VirtualBox Host-Only Ethernet Adapter #2' with ip 172.28.128.3  


If I create a new VM, with the same configuration, on my machine I am used, Windows 10 Host, got in the same network:

$ vagrant ssh -c 'ifconfig eth1'
eth1      Link encap:Ethernet  HWaddr 08:00:27:f7:c1:74
          inet addr:172.28.128.4  Bcast:172.28.128.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fef7:c174/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1180 (1.1 KB)  TX bytes:1152 (1.1 KB)

so both VMs are on the same private network, so they will see each other over that ip.

From here,

- What do you want to do?
- What do you see is happening ?
- What do you think is right / wrong ?

Thanks!
Alvaro.


--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/48dc8664-53d0-497a-81fa-ad12d5d20346%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

ben sholdice

unread,
Mar 10, 2017, 2:01:25 PM3/10/17
to Vagrant
Hi Alvaro
thank you for your patient and detailed response. I see you helping others on this list so thank you for the time and effort you give to help others, it is appreciated!

what follows is an attempt to structure my issue so it is reproducible. it does not exactly fit my original problem in my first post, but resolving it will help me immensely. I followed your example where you use the VirtualBox manager (GUI) to create a hostonlyif and a DHCP server running on that hostonlyif. Then you create two VMs and confirm both are connected to that hostonlyif and are getting an IP address from the DHCP service you created. I got the same result as you. So far so good.

I want to create a third VM that uses an entirely different hostonlyif. So I create a second hostonlyif (vboxnet1) with its own DHCP service (offering, say, ips from the range 192.168.57.100 through 192.168.57.199). Now my VirtualBox hostonlyifs & dhcpserver list looks like this:

macbook: VBoxManage list hostonlyifs
Name:            vboxnet0
GUID:            786f6276-656e-4074-8000-0a0027000000
DHCP:            Disabled
IPAddress:       172.28.128.1
NetworkMask:     255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0

Name:            vboxnet1
GUID:            786f6276-656e-4174-8000-0a0027000001
DHCP:            Disabled
IPAddress:       192.168.57.1
NetworkMask:     255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:01
MediumType:      Ethernet
Status:          Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet1

macbook: VBoxManage list dhcpservers
NetworkName:    NatNetwork
IP:             10.0.2.3
NetworkMask:    255.255.255.0
lowerIPAddress: 10.0.2.4
upperIPAddress: 10.0.2.254
Enabled:        Yes

NetworkName:    HostInterfaceNetworking-vboxnet0
IP:             172.28.128.2
NetworkMask:    255.255.255.0
lowerIPAddress: 172.28.128.3
upperIPAddress: 172.28.128.254
Enabled:        Yes

NetworkName:    HostInterfaceNetworking-vboxnet1
IP:             192.168.57.1
NetworkMask:    255.255.255.0
lowerIPAddress: 192.168.57.100
upperIPAddress: 192.168.57.199
Enabled:        Yes

Then I create third Vagrant VM and configure it to have two interfaces - eth0 on the ubiquitous NAT network (for vagrant control), and eth1 on this new vboxnet1. Based on your previous suggestion you would recommend the that the Vagrantfile will look like this:

Vagrant.configure("2") do |config|
  config.vm.box = "nrel/CentOS-6.6-x86_64"
  config.vm.network "private_network", type:"dhcp", name: "vboxnet1"
end


But, my new third VM does not attach to vboxnet1. In fact, it attaches to vboxnet0, as seen by selected output of the command 'VAGRANT_LOG=info vagrant up --provision'
==> default: Preparing network interfaces based on configuration...
 INFO interface: detail: Adapter 1: nat
 INFO interface: detail:     default: Adapter 1: nat
    default: Adapter 1: nat
 INFO interface: detail: Adapter 2: hostonly
 INFO interface: detail:     default: Adapter 2: hostonly
    default: Adapter 2: hostonly
 INFO subprocess: Starting process: ["/usr/local/bin/VBoxManage", "modifyvm", "0f7f7d39-c0f6-4916-87dc-67dc5ff526ba", "--nic1", "nat", "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet0", "--cableconnected2", "on"]
[...]

and sure enough, this new third vm is getting an IP (172.28.128.3)  from the DHCP service running on vboxnet0
macbook:  vagrant ssh -c "ip addr"
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:1b:06:06 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
    inet6 fe80::a00:27ff:fe1b:606/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:00:00:4b brd ff:ff:ff:ff:ff:ff
    inet 172.28.128.3/24 brd 172.28.128.255 scope global eth1
    inet6 fe80::a00:27ff:fe00:4b/64 scope link
       valid_lft forever preferred_lft forever
Connection to 127.0.0.1 closed.

so my first question is: what vagrantfile vm.network command binds the private_network to the desired hostonlyif vboxnet1?
my second question is: where in the vagrant documentation is this vm.network command syntax listed? I don't see anything on https://www.vagrantup.com/docs/networking/private_network.html

in fact the documentation seems frustratingly sparse. where can I find all available syntax for the Vagrantfile vm.network directive?


FYI my versions:
macOS Sierra: 10.12.3 (16D32)
Vagrant: 1.9.2
VBoxManage: 5.1.16r113841

Thank you again for your help!!
Ben
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.



--
Alvaro

ben sholdice

unread,
Mar 10, 2017, 2:14:00 PM3/10/17
to Vagrant
moments after I posted this reply I looked at the provider-specific vagrant configuration and tried to do some virtualbox-specific config to force hostonlyadapter2 onto my vboxnet0. 

Vagrant.configure("2") do |config|
  config.vm.box = "nrel/CentOS-6.6-x86_64"
  config.vm.network "private_network", type: "dhcp", name: "vboxnet1"
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--hostonlyadapter2", "vboxnet1"]
  end
end

I still see this in the debug output:
==> default: Preparing network interfaces based on configuration...
 INFO interface: detail: Adapter 1: nat
 INFO interface: detail:     default: Adapter 1: nat
    default: Adapter 1: nat
 INFO interface: detail: Adapter 2: hostonly
 INFO interface: detail:     default: Adapter 2: hostonly
    default: Adapter 2: hostonly
 INFO subprocess: Starting process: ["/usr/local/bin/VBoxManage", "modifyvm", "0f7f7d39-c0f6-4916-87dc-67dc5ff526ba", "--nic1", "nat", "--nic2", "hostonly", "--hostonlyadapter2", "vboxnet0", "--cableconnected2", "on"]


but now I also see this:
==> default: Running 'pre-boot' VM customizations...
 INFO subprocess: Starting process: ["/usr/local/bin/VBoxManage", "modifyvm", "0f7f7d39-c0f6-4916-87dc-67dc5ff526ba", "--hostonlyadapter2", "vboxnet1"]
 INFO subprocess: Command not in installer, restoring original environment...
 INFO warden: Calling IN action: #<VagrantPlugins::ProviderVirtualBox::Action::Boot:0x000001021e0200>
 INFO interface: info: Booting VM...
 INFO interface: info: ==> default: Booting VM...

and sure enough, mv VM has an eth1 interface picking up an IP address from vboxnet1. So this worked, but I'm sure I don't need to dive into provider syntax for something as simple as setting the right hostonlyif network?

Ben

Alvaro Miranda Aguilera

unread,
Mar 10, 2017, 5:12:46 PM3/10/17
to vagra...@googlegroups.com
hey hey hye :D

you moving fast

That worked fine

The trick now is, where do you think this information should be / where you would expect to see it in the documentation?

And we can add it with a pull request and include it with the example.

nice finding

Alvaro

To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/792096cf-eaa3-4af6-8477-d8c044d62fb3%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Alvaro

Reply all
Reply to author
Forward
0 new messages