hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.2k stars 4.43k forks source link

Vagrant errors when specifying custom Host-Only attached adapter network #8878

Open ggeldenhuis opened 7 years ago

ggeldenhuis commented 7 years ago

Vagrant version

Vagrant 1.9.7

Host operating system

OSX 10.11.6

Guest operating system

Ubuntu 16.04 CentOS 7

Virtualbox version

5.1.26 r117224 (Qt5.6.2)

Vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

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

  config.vm.define "landscape01" do |landscape01|
    landscape01.vm.box = "puppetlabs/centos-7.2-64-puppet"
#    landscape01.vm.box = "puppetlabs/ubuntu-16.04-64-nocm"
#    landscape01.vm.box = "ubuntu/xenial64"
    landscape01.vm.hostname = "landscape01.example.com"
#    config.vm.network "private_network", :type => 'dhcp', virtualbox__intnet: "vboxnet0",
    config.vm.network "private_network", :type => 'dhcp', :name => 'vboxnet1'
#    config.vm.network "private_network", :type => 'dhcp'

    config.vm.provider "virtualbox" do | vf |
      vf.gui = true
      vf.memory = 4096
      vf.cpus = 4
    end
  end

end

Debug output

https://gist.github.com/ggeldenhuis/ebfd3db970892a24f5bbff691d7e2e9d

Expected behavior

The expectation is that two network adaptors should be created in Virtualbox. The first should be attached to the NAT network and allow the machine out bound connectivity. The second adapter should be attached to the Host-Only adapter connected to the vboxnet1 network.

Actual behavior

I get an error: 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.

Steps to reproduce

  1. Empty Virtualbox off all machines. Ensure there is only 2 vboxnet networks.
  2. Configure vboxnet1 to a custom dhcp range. I used 192.168.254.0/24
  3. vagrant up --provider=virtualbox

If you omit the name of the network vagrant will create a new vboxnet2 network and attach the adapter to that network.

Destroy the VM. Modify the vboxnet2 network to be a different range. Now specify the name as vboxnet2 and run vagrant up. The same error occurs.

It appears that vagrant does not like my custom networks and gives an error when I try to use them. If I don't modify the network then it all works fine.

I have been able to reproduce this with three different box files as shown in the config file above.

References

RyanKoppenhaver-NCC commented 6 years ago

I encountered the same issue, and was able to work around it by adding the following monkey patch to the top of my Vagrantfile:

class VagrantPlugins::ProviderVirtualBox::Action::Network
  def dhcp_server_matches_config?(dhcp_server, config)
    true
  end
end
geez0r commented 6 years ago

Ryan - thank you, added your snippet to the top of Vagrantfile and this resolved the issue for me, now VBox/Vagrant does not create the extra vboxnet rather uses the already existing one. Quite annoying though.
Regards and kudos.

den-is commented 6 years ago

+1 encountered same issue. strange that still nothing has been done about it. very useful when you have your own well defined networks and you know what IPs/etc to expect.

Vagrant 2.1.5 Virtualbox 5.2.18 on macbook pro, macos 10.13.6 (17G65)

sushlala commented 5 years ago

Ran into this too. Vagrant 2.2.0 Virtual Box 5.2.2 The monkey patch worked for me

frankfuu commented 4 years ago

I also ran into this.

Host O/S - Ubuntu 18.04.3 LTS Guest O/S - bento/ubuntu-18.04

Vagrant 2.2.5 Virtualbox 6.0.12r133076

Applied the monkey patch at the bottom of my vagrant file and worked.

OperationalDev commented 4 years ago

I also had this issue:

Host O/S: Windows 10 Pro Guest O/S: Rhel 7

Vagrant: 2.2.5 Virtualbox: 5.2.16

Monkey patch worked for me.

markhann commented 4 years ago

Monkey patch worked on: Vagrant 2.2.6 Virtualbox 6.1.0 (thanks to https://github.com/oracle/vagrant-boxes/issues/178#issue-536720633) Host: macOS 10.15.2 Guest: Ubuntu 18.04

taupecat commented 4 years ago

This is coming up consistently for me upon upgrading to 2.2.7 and VirtualBox 6.1 (but never before). The snippet seems to be working. Thanks.

BronsonQuick commented 4 years ago

I hit this one yesterday setting up a new machine for a friend with the latest VirtualBox and Vagrant and the monkey patch worked for her.

den-is commented 4 years ago

I have tested that yesterday. And all worked good. macos 10.14.6 Virtualbox 6.1.2 r135662 w/ extensions vagrant 2.2.7 guest centos7

I'm setting private network. ANd in addition to that I assign nodes with static predefined IPs

      node.vm.network "private_network", ip: my_host_settings_map["ip"]
wwalker commented 4 years ago

I hit this today too.

The work around that @RyanKoppenhaver-NCC provided worked. But...

Mike-N5BGZ commented 4 years ago

I hit this today and RyanKoppenhaver-NCC monkey patch (see further up the trail) worked perfectly. And +1 on the comments of "why has this not been fixed?'!!! I spent over an hour trying to get this to work so I could use a vagrant file for a training class.

j3mdamas commented 4 years ago

I was redirected here from https://github.com/hashicorp/vagrant/issues/11364. Unfortunately I don't have time to test this again. I reverted to VirtualBox 6.0.16 and it works for me. I hope this information helps.

phillipross commented 4 years ago

Today was the first day I've seen this error, only after updating from vagrant v2.2.6 to v2.2.7 and from virtualbox v6.0.16 to v6.1.2. Applying the patch from https://github.com/hashicorp/vagrant/issues/8878#issuecomment-345112810 did work around the issue, but I also tested moving back to virtualbox v6.0.16 and it worked again without needing the patch in Vagrantfiles.

Platform: MacOS 10.14.6

mathiasaerts commented 4 years ago

Could be related to #11403 for anyone using Vagrant 2.2.7 with Virtualbox 6.1. A fix has been merged to master and will be included in the next release.

rezagh commented 4 years ago

any ETA for 2.2.8 ?

return42 commented 4 years ago

Is there any workaround as long as we do not have a new release?

j3mdamas commented 4 years ago

@return42 this has been claimed to be a work-around

return42 commented 4 years ago

@j3mdamas thanks! / I should have read it .. :man_facepalming:

dotboris commented 4 years ago

I've done some debugging on this and I've managed to get closer to a root cause.

Note that I'm running vagrant v2.2.7 and virtualbox 6.1.6 on OSx.

I've added the following code to my VagrantFile

class VagrantPlugins::ProviderVirtualBox::Action::Network
  alias_method :old_dhcp_server_matches_config?, :dhcp_server_matches_config?
  def dhcp_server_matches_config?(dhcp_server, config)
    p 'dhcp_server_matches_config?', dhcp_server, config
    old_dhcp_server_matches_config?(dhcp_server, config)
  end

  alias_method :old_find_matching_dhcp_server, :find_matching_dhcp_server
  def find_matching_dhcp_server(interface)
    p 'find_matching_dhcp_server', interface
    res = old_find_matching_dhcp_server(interface)
    p res
    res
  end
end

With this I get the following output:

Bringing machine 'master' up with 'virtualbox' provider...
==> master: Checking if box 'ubuntu/bionic64' version '20200626.0.0' is up to date...
==> master: Clearing any previously set network interfaces...
"find_matching_dhcp_server"
{:name=>"vboxnet0", :ip=>"10.0.99.1", :netmask=>"255.255.255.0", :ipv6=>"", :ipv6_prefix=>"0", :status=>"Up"}
[{:network=>"vboxnet0", :network_name=>"HostInterfaceNetworking-vboxnet0", :netmask=>"255.255.255.0"}]
{:network=>"vboxnet0", :network_name=>"HostInterfaceNetworking-vboxnet0", :netmask=>"255.255.255.0"}
"dhcp_server_matches_config?"
{:network=>"vboxnet0", :network_name=>"HostInterfaceNetworking-vboxnet0", :netmask=>"255.255.255.0"}
{:adapter_ip=>"10.0.99.1", :auto_config=>true, :ip=>"10.0.99.3", :mac=>nil, :name=>nil, :netmask=>"255.255.255.0", :nic_type=>nil, :type=>:dhcp, :dhcp_ip=>"10.0.99.2", :dhcp_lower=>"10.0.99.20", :dhcp_upper=>"10.0.99.254", :adapter=>2}
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.

It looks like the dhcp_server_matches_config? function that is being monkey patched in the "workaround" is given too little information to be able to do its job.

Here's how it's defined:

https://github.com/hashicorp/vagrant/blob/b886ec0b323163920202baec6424b64ccfcc56bc/plugins/providers/virtualbox/action/network.rb#L538-L548

It clearly needs the :ip, :lower and :upper keys which are not present when you look at the output that I'm getting.

When I dig a little deeper, it seems that the function responsible for finding the dhcp server settings (find_matching_dhcp_server) is not returning all of those fields as it should.

Following the code leads me to the read_dhcp_servers function of the 6.1 VirtualBox driver.

https://github.com/hashicorp/vagrant/blob/a10b2c3108d1e5720ae7ea2317b8e0b5172d2b0e/plugins/providers/virtualbox/driver/version_6_1.rb#L14-L35

I can't tell what the problem is by just looking at the code. When I run VAGRANT_LOG=debug vagrant up ... on my end, I can fish out the following output.

 INFO subprocess: Starting process: ["/usr/local/bin/VBoxManage", "list", "dhcpservers"]
DEBUG subprocess: Command not in installer, not touching env vars.
 INFO subprocess: Command not in installer, restoring original environment...
DEBUG subprocess: Selecting on IO
DEBUG subprocess: stdout: NetworkName:    HostInterfaceNetworking-vboxnet0
Dhcpd IP:       10.0.99.2
LowerIPAddress: 10.0.99.20
UpperIPAddress: 10.0.99.254
NetworkMask:    255.255.255.0
Enabled:        Yes
Global Configuration:
    minLeaseTime:     default
    defaultLeaseTime: default
    maxLeaseTime:     default
    Forced options:   None
    Suppressed opts.: None
        1/legacy: 255.255.255.0
Groups:               None
Individual Configs:   None
DEBUG subprocess: Waiting for process to exit. Remaining to timeout: 32000
DEBUG subprocess: Exit status: 0

It seems like the output is all there but the parsing of those fields fails somehow.

I'd really like this to get fixed because I'm really not fond of the workaround proposed above. That workaround disables all sanity checking on the DHCP server and systematically re-uses the same DHCP server every time even tho they might conflict.

dotboris commented 4 years ago

There's actually a solution out! This was fixed in a10b2c3108d1e5720ae7ea2317b8e0b5172d2b0e which was released under v2.2.9 🎉

I upgraded my local version of vagrant to v2.2.9 and it's all fixed now. 🎉

HiMyNameIsIlNano commented 2 years ago

@dotboris I am not sure that is 100% accurate. In my case the problem just manifested with Virtualbox Version 6.1.28 r147628 and Vagrant 2.2.19

EduardoRezes commented 2 years ago

@dotboris I am not sure that is 100% accurate. In my case the problem just manifested with Virtualbox Version 6.1.28 r147628 and Vagrant 2.2.19

I have the same configuration, but my Virtual Box Version 6.0.24 r139119 and Vagrant the same.

mklassen commented 2 years ago

If you specify the DHCP configuration in the Vagrantfile, i.e. matching the DHCP configuration of the vboxnet3 being used, then the error goes away for me.

config.vm.network "private_network", type: "dhcp", netmask: "255.255.0.0", name: "vboxnet3", dhcp_ip:"10.101.0.2", dhcp_lower: "10.101.4.3", :dhcp_upper=>"10.101.4.254"

If you do not specify the netmask, dhcp_ip, dhcp_lower, dhcp_upper, then vagrant tries to use the default 255.255.255.0, 10.101.0.2, 10.101.0.3, 10.101.0.254 and since these DHCP configuration values do not agree with my vboxnet3 DHCP setting the error is generated.

ed3899 commented 1 year ago

If you specify the DHCP configuration in the Vagrantfile, i.e. matching the DHCP configuration of the vboxnet3 being used, then the error goes away for me.

config.vm.network "private_network", type: "dhcp", netmask: "255.255.0.0", name: "vboxnet3", dhcp_ip:"10.101.0.2", dhcp_lower: "10.101.4.3", :dhcp_upper=>"10.101.4.254"

If you do not specify the netmask, dhcp_ip, dhcp_lower, dhcp_upper, then vagrant tries to use the default 255.255.255.0, 10.101.0.2, 10.101.0.3, 10.101.0.254 and since these DHCP configuration values do not agree with my vboxnet3 DHCP setting the error is generated.

Looks to be working for me, changing of course the values according to the ones from my VirtualBox > Tools