Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ggeldenhuis opened this issue Aug 11, 2017 · 25 comments
Open

Comments

@ggeldenhuis
Copy link

ggeldenhuis commented Aug 11, 2017

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

@ggeldenhuis ggeldenhuis changed the title Host-Only network issues when creating Virtualbox machine Vagrant errors when specifying custom Host-Only attached adapter network Aug 11, 2017
@RyanKoppenhaver-NCC
Copy link

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
Copy link

geez0r commented Dec 16, 2017

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
Copy link

den-is commented Sep 22, 2018

+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)

@sush-abc
Copy link

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

@frankfuu
Copy link

frankfuu commented Oct 16, 2019

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
Copy link

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
Copy link

markhann commented Dec 31, 2019

Monkey patch worked on:
Vagrant 2.2.6
Virtualbox 6.1.0 (thanks to oracle/vagrant-projects#178 (comment))
Host: macOS 10.15.2
Guest: Ubuntu 18.04

@taupecat
Copy link

taupecat commented Feb 1, 2020

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
Copy link

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
Copy link

den-is commented Feb 3, 2020

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"]

matyasselmeci added a commit to matyasselmeci/vagrant-templates that referenced this issue Feb 5, 2020
@wwalker
Copy link

wwalker commented Feb 5, 2020

I hit this today too.

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

@Mike-N5BGZ
Copy link

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
Copy link

I was redirected here from #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
Copy link

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 #8878 (comment) 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

@briancain briancain added this to the 2.2 milestone Feb 14, 2020
@mathiasaerts
Copy link

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
Copy link

rezagh commented Apr 9, 2020

any ETA for 2.2.8 ?

@return42
Copy link

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

@j3mdamas
Copy link

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

@return42
Copy link

@j3mdamas thanks! / I should have read it .. 🤦‍♂️

@dotboris
Copy link

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:

# Detect when an existing DHCP server matches precisely the
# requested config for a hostonly interface.
#
# @param [Hash<String>] dhcp_server as found by read_dhcp_servers
# @param [Hash<String>] config as returned from hostonly_config
# @return [Boolean]
def dhcp_server_matches_config?(dhcp_server, config)
dhcp_server[:ip] == config[:dhcp_ip] &&
dhcp_server[:lower] == config[:dhcp_lower] &&
dhcp_server[:upper] == config[:dhcp_upper]
end

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.

def read_dhcp_servers
execute("list", "dhcpservers", retryable: true).split("\n\n").collect do |block|
info = {}
block.split("\n").each do |line|
if network = line[/^NetworkName:\s+HostInterfaceNetworking-(.+?)$/, 1]
info[:network] = network
info[:network_name] = "HostInterfaceNetworking-#{network}"
elsif ip = line[/^Dhcpd IP:\s+(.+?)$/, 1]
info[:ip] = ip
elsif netmask = line[/^NetworkMask:\s+(.+?)$/, 1]
info[:netmask] = netmask
elsif lower = line[/^LowerIPAddress:\s+(.+?)$/, 1]
info[:lower] = lower
elsif upper = line[/^UpperIPAddress:\s+(.+?)$/, 1]
info[:upper] = upper
end
end
info
end
end

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
Copy link

There's actually a solution out! This was fixed in a10b2c3 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
Copy link

@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
Copy link

@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
Copy link

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
Copy link

ed3899 commented Mar 24, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests