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

Host-Only-Adapter has wrong IP and subnetmask #1014

Closed
athiele opened this issue Jul 11, 2012 · 9 comments
Closed

Host-Only-Adapter has wrong IP and subnetmask #1014

athiele opened this issue Jul 11, 2012 · 9 comments

Comments

@athiele
Copy link

athiele commented Jul 11, 2012

When starting a box with host-only-networking, sometimes the created virtual network adapter in VirtualBox has a different IP and subnetmask than specified. That causes the problem, that if I start an other box of our Vagrant environment, VirtualBox registers a "Virtualbox Host Only Adapter #2", #3, etc. This prevents the different VMs from communicating with each other, because the first VMs network card is "Virtualbox Host Only Adapter", and the second VMs adapter is "Virtualbox Host Only Adapter #2".

This problem occurs sporadically on different hosts with Windows 7. After rebooting the host machine, the error usually does not occur anymore.

The Vagrantfile we use:

Vagrant::Config.run do |config|
  config.vm.define :management do |man_config|

    [...]
    man_config.vm.boot_mode = :headless
    man_config.vm.network :hostonly, "192.168.0.10", :netmask => "255.255.255.0"
    man_config.vm.customize ["modifyvm", :id, "--memory", 2200]
    man_config.vm.customize ["modifyvm", :id, "--cpus", 2]
    [...]
  end
[..] 
end

In the Virtualbox Console, "VirtualBox Host-Only Ethernet Adapter" has the following properties:

IPv4 address: 169.254.130.104
IPv4 netmask: 255.255.0.0

We found this workaround, to force the VMs to use one network adapter, even if it has the wrong ip data :
man_config.vm.customize ["modifyvm", :id, "--nic2", "hostonly", "--cableconnected2", "on", "--hostonlyadapter2", "VirtualBox Host-Only Ethernet Adapter"]

This workaround is very helpful but it seems to be not a clean solution for permanent usage.

Software in Use:
Windows 7 64bit
Vagrant 1.0.3
VirtualBox 4.1.16

Thanks in advance and kind regards
Aimo

@mgeens
Copy link

mgeens commented Jul 30, 2012

I had the same issue with a Vagrantfile that had 2 machines that each used :hostonly with just an IP specified. It worked well for several weeks, but today I ran into it. After a reboot and recreating the machines it worked again.

Versions:
Windows 7 64-bit
Vagrant 1.0.2
VirtualBox 4.1.18

@fsimmend
Copy link

seems like this bug https://www.virtualbox.org/ticket/8796

@oliverhr
Copy link

oliverhr commented Apr 4, 2013

I have the same issue.

I think is because Vagrant can't identify a matching host-only network adapter and create a new one. no matter what even if the last host-only network adapter is still there.

This issue is on windows as host, because with the same configuration on a Linux machine as host everything run as expected.

  • Vagrant version: 1.1.5 for windows
  • Host: windows 7 64 bit
  • Guest: centOS 6.4 32 bit
  • VirtualBox 4.2.10 r84104

Greetings from Mexico.

@fsimmend
Copy link

actually the problem is windows specific and you cannot fix it within the vagrant file. The problem manifests when you destroy and recreate the adapter via the vboxmanage.exe. Under some circumstances windows will then give your adapter an APIPA address (169.254.x.x) and the default subnet mask 255.255.0.0 .You cannot change this behaviour.

A tricky workaround, that works great is to create a dummy box in virtual box that uses a hostonly adapter with the correct ip and subnet, then vagrant won't delete and recreate the adapter and cannot run into that problem.

The workaround also prevents you from clicking the annoying UAC popup all the time. On the ChefConf i talked with Mitchell and he will probably create a switch to prevent vagrant from deleting and recreating the adapter.

@hugomrdias
Copy link

my take on this, you need 2 things:
1 - disable "Network Activity Hook lightweight filter driver" in the adapter properties
2 - VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter #2" --ip XX.XX.XX.XX --netmask 255.255.255.0

the first step dont ask me ... virtualbox create the adapter with that driver on and it fucks everything up.

the second step its weird too... if you change the ip and net mask in the GUI it only lets you define a 255.255.0.0 mask other than that it will not save. but with the CLI command it works! so add the virtualbox folder to the PATH and run the cmd with the ip and net mask you want.

after that if the ip on your vagrantfile is in the same range of the one you define in the step 2 go ahead and vagrant up. Vagrant will use "VirtualBox Host-Only Ethernet Adapter #2" and will not create a new one.

@mitchellh
Copy link
Contributor

Based on everything I've read here as well as the evidence put forward, I'm going to say this is a VirtualBox bug. What Vagrant does when you specify a host only network is look for a matching one and use it. In this case, it looks like VirtualBox isn't properly keeping the settings set, and therefore it no longer matches.

If I'm wrong, feel free to add more. Thanks

@rogersanctus
Copy link

Well, I had the same problem on windows 8.1, but I just had to rerun the vagrant up command again and it worked xD.

@berpcor
Copy link

berpcor commented Mar 23, 2016

The same problem. I upgraded Virtualbox and Vagrant to the latest versions, and thus I created problems for me. Downgrade doesn't help. Every time I do vagrant up, vagrant creates a new host-only adapter with the wrong settings.

  config.vm.network :private_network, ip: 192.168.56.56
  config.vm.network :forwarded_port, guest: 80, host: 8000
  config.vm.network :forwarded_port, guest: 9200, host: 9200

IP and mask for a new adapter (if it doesn't exists) should be 192.168.56.1 and 255.255.255.0 but like it is said above it is (169.254.x.x). So I can't visit guest by its IP.

I try to change settings of host-only adapter in Virtualbox, but it reset it to 169.254.x.x again. The only thing that helped me is manual changind ipv4 settings of virtual host-only adapter and after turn off/turn on this adapter and after reloading vagrant everything begins to work like before.

What does all that mean? I shouldn't use private network anymore?

@berpcor
Copy link

berpcor commented Mar 31, 2016

I have the latest versions of Vagrant and Virtualbox. What is solution for this problem now? Virtualbox is guilty or not, the problem still exists. Somebody do something or tell me what is the best practice to solve problem for now.

@ghost ghost locked and limited conversation to collaborators Apr 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants