Sam Trenholme's webpage
Support this website

VirtualBox’s host-only adapter

 

August 26 2013

How to fix VirtualBox’s host-only adapter when it breaks down in Windows 7.

==VirtualBox==

VirtualBox is an emulator that allows an entire virtual computer running its own operating system (called a guest) to run as a program inside an actual computer (the host) running either the same or another operating system. It allows me to run Linux and Windows at the same time on the same computer.

==Networking with VirtualBox==

It is best if the machine running in VirtualBox is in its own virtual network, so that I can both:

  • Use SSH to access the Linux virtual machine from Windows
  • Have the Virtual machine run regardless of the network the host computer is in.
  • If the host computer has Internet, the virtual machine should also have Internet connectivity.

To do this in Virtual Box, the machine needs to have two network adapters enabled:

  • A NAT adapter to give the virtual machine Internet access
  • A host-only adapter to allow SSH access from PuTTY on the Windows host.

Ifconfig looks like this on my Linux virtual machine:

eth1      Link encap:Ethernet  HWaddr 08:00:27:7A:32:A4
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0

Some redundant data removed

eth2      Link encap:Ethernet  HWaddr 08:00:27:5F:03:F9
          inet addr:10.0.5.15  Bcast:10.0.5.255  Mask:255.255.255.0

Eth1 is the host-only adapter; I use this to connect to the box using PuTTY on the Windows host and sshd (openssh-server) in the Linux host. The Windows host, on the eth1 adapter in Windows, has the IP 192.168.56.2. When I connect to 192.168.56.101, Windows uses a special virtual Ethernet adapter called the "VirtualBox Host-only Ethernet Adapter" to connect to the virtual machine.

Here is the output of "route" on the virtual machine:

Destination     Gateway         Genmask         Iface
10.0.5.0        *               255.255.255.0   eth2
192.168.56.0    *               255.255.255.0   eth1
default         10.0.5.2        0.0.0.0         eth2

The Ethernet adapter eth2 connects the virtual machine to the Internet via the host computer’s Internet connection because it uses a “NAT” adapter.

==Setting up the network in VirtualBox==

Network adapter settings can only be altered in VirtualBox when the virtual machine is powered off. Once the virtual machine has Linux installed on it and is powered off, click on the yellow “settings” gear button after selecting the Linux virtual machine. Next, click on the network button. Make “Adapter 1” be a NAT adapter, and “Adapter 2” be a host-only adapter. Make sure the check box "Cable connected" is checked, and power up the Linux virtual machine.

Once the Linux virtual machine is powered up, the virtual networks can be enabled by running this as root:

dhclient eth0 eth1

==The host-only network stops working!==

Unfortunately, there is a bug with VirtualBox’s host-only network adapter which makes it stop running in Windows. Rob Boek blogged about the solution so the network adapter works again:

  • Run regedit
  • Go to HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Class\ {4AD36E972-E325-11CE-BFC1-08002BE10318}
  • There will be a bunch of folders with names like "0000", "0001", and so on.
  • Look for the folder with a key named "DriverDesc" with the value "VirtualBox Host-Only Ethernet Adapter" in the folder
  • Create a new Dword (32-bit) called "*NdisDeviceType" (yes, it needs to start with a star) and a value of 1, in the same folder with the "DriverDesc" of "VirtualBox Host-Only Ethernet Adapter"
  • Disable then enable the VirtualBox host-only adapter.

Some more information is in a MSDN article.

Warning: Regedit is a very dangerous tool. Making a mistake here can make it necessary to reinstall one’s operating system. Use at your own risk!

Once the above is done, make sure the host-only adapter has a good IP and DHCP server settings by going to, in VirtualBox, File -> Preferences -> Network

==Conclusion==

It took me over an hour of research to find this solution to VirtualBox’s host-only network problems in Windows 7. I hope this blog entry helps the next Linux + Windows power user with the same problem.

To post a comment about an entry, send me an email and I may or may not post your comment (with or without editing)