How To Enable DHCP in VirtualBox 4.0.4

Virtualization seems to be the buzzword these days and the software that makes its adoption painless for ordinary folks, in my opinion, is Oracle”s VirtualBox. It may not be “there” yet with VMWare, wherever “there” is, but for a basic testing lab, VBox does an awesome job. The software is free – no one asks you to sign anything, fill out a long form, hand over your kids, or agree to some hidden EULA before you download. Go to the website, look for the version that matches your platform and download.

If you are using a Linux Operating System, VirtualBox is most likely in the repository of your distro. From the website: “VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL) version 2”.

That is the way free should be.

VirtualBox runs on Windows, Linux, Macintosh and OpenSolaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, Windows 7), DOS/Windows 3.x, Linux (2.4 and 2.6), Solaris and OpenSolaris, and OpenBSD. The latest version is 4.0.4.

Unfortunately, this latest version breaks DHCP so you cannot use the “Internal Network” feature – a must have, if you are using Virtualbox as a test environment. On a Windows server 2008 with 16GB of RAM and 2TB of hard drive space, we are running about 25 virtual machines – Linux, OpenSolaris, Windows, virtual appliances like Vyatta and GNS3 for routing, Joomla! websites, SugarCRM, FreeDOS etc.

Virtualization is indeed a good thing, especially for testing pesky software and not to be trusted Service Packs! VirtualBox allows up to four virtual network adapters so if you want to venture outside the walls of your internal network, just enable a second adapter and use the “NAT” option to gain internet access. The beauty of the internal network feature is that all your virtual machines are in their own world with RFC 1918 IP addresses. But for this to work, DHCP needs to be working and this is where we run into some problem.

DHCP on the previous versions worked “out-of-the-box” so we were a little bit at a loss as to why we were not connecting. Before subjecting myself to being yelled at in a forum, I decided to RTFM and there is was. Chapter 8, section 33 – ” 8.33. VBoxManage dhcpserver” if you use the help content in Virtualbox, or here in the online manual, there are instructions on how to enable DHCP in VirtualBox 4.0.4.

The command is:

VBoxManage dhcpserver add –netname (the internal network name e.g. intnet) –ip <your RFC 1918 address> (e.g. 192.168.x.x, 10.x.x.x, 172.16.x.x) –netmask <your subnet mask> (e.g. –lowerip <your lower IP range> (e.g. –upperip <your upper IP range> (e.g. — enable

So for example, your entry could look like this:

VBoxManage dhcpserver add –netname intnet –ip –netmask –lowerip –upperip –enable (all on one long line)

The first IP address, which is in our example, is the address of the DHCP server itself, next is the range you want to use hence lowerip/upperip. My suggestion is to power off your virtual machine(s) and close the VirtualBox application before running the command. By the way, this should be done on the “Host” operating system (we are going to assume Windows, sorry) not on the guest.

If you get this error: “VBoxManage is not recognized as an internal command”, most likely you are trying to run the command on the guest machine. The DHCP service has to be set up on the host side. In Windows, open command prompt and change directory (cd) to the VirtualBox directory – e.g cd “Program FilesOracleVirtualBox” (version 4 is the Oracle version, but just in case you have an older version with the same issue, that version may still be using the Sun directory. If you are using Windows Vista or 7, you may need to run the command prompt as administrator – right-click the command prompt, select “Run as administrator”.

Reopen the VirtualBox application and power on your virtual machine(s). If your VMs do not pick up addresses from the DHCP server, right-click on your network icon and select “repair” (XP) or “diagnose” Vista and 7). This fixed the addressing issue for us and allowed us to use the internal network option. Your experience may vary.