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:
To do this in Virtual Box, the machine needs to have two network adapters enabled:
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:
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
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)