Creating a Virtual Network with VirtualBox

VirtualBox sure is a great virtualization tool; not yet at the level of VMWare, but it’s getting very close, and esp. for basic day-to-day programming, when all you need is an “alien” test/development system, it’s a very adequate tool to use, and rivals VMWare’s performance quite nicely, and it’s free as in beer.

One thing it still lags a bit behind is the amount of settings you can access from GUI; it’s not as much trouble of quantity as of organization.

Here is what my goal was – couple of Ubuntu 9.10 server installations, that are on a “local” network, and can “see” each other. Yes, that’s it. The purpose is obvious – test “production” platform to see how it works and scales. The host platform was Ubuntu 9.10 desktop edition (yeah, I’m neck deep in Ubuntu ;)).

Just a side note – Ubuntu 9.10 server edition surprised me on many points, my next desktop installation will probably be Ubuntu server itself; the ease of setup, loads of options, and the tiny initial disk and memory footprint are just lovable. Plus it comes with all the little bells and whistles that make life so much easier in desktop edition, and make you file at home!

OK, 3 virtual machines set up, each with 2 network adapters – Adapter 1 (eth0) – being the local network – Internal Network, called intnet by default, leaving it as is, and Adapter 2 (eth1) – NAT to Internet.
Now, ifconfig… Hmm, no eth0. It’s down (ifconfig -a sees eth0). dhclient refuses to talk to me… I mean, host. eth1 works like a charm, I have net, DHCP works just fine automatically on the system start up.

So, I turn them all off, switch to Host-Only network on Adapter 1 on all machines, fire them up. ifconfig still does not show eth0. But yay, dhclient grabs an address!… Oh, stop, it’s the same address on all 3 machines! Something’s rotten here.

So, I return to Internal Network, and grab a VBoxManage manual.

To make all this work, you need to create DHCP server for the machines, and configure it (why it’s not done, no idea):

VBoxManage dhcpserver add --netname intnet --ip \
    --netmask --lowerip --upperip

Above, is IP of the DHCP server itself, the rest is obvious. You don’t even need to feed this to dhclient via -s option, VBox redirects it to this server automatically.

Yeah, that’s all, but for some, not obvious to me, reason, this is not done by VBox itself. I didn’t even create new network, it was implicitly selected by VBox. After this, dhclient grabs an address right away, unique for each machine, and ping is in rank of 1ms. Neato!

To end this with a tiny rant – why it’s not automated, VBox, why?!
Otherwise, great work, VBox! 🙂

4 responses to “Creating a Virtual Network with VirtualBox

  1. and don’t forget –enable at the end of the line after –upperip otherwise dhcp server will be created in OFF mode and will not hand out IP addresses

  2. I don’t like anything static, as I might afterwards just “temporarily” use the static address somewhere in code, and forget about it afterwards… Some of the worst bugs to hunt down, the “works for me” kind.

  3. So I type in the command with enable at the end like one of the posters says.

    This is the reponse I get (On a Windows7 host, with a W7 VM):

    VBoxManage.exe: error: Failed to create the VirtualBox object!
    VBoxManage.exe: error: Code CO_E_SERVER_EXEC_FAILURE (0x80080005) – Server execu
    tion failed (extended info not available)
    VBoxManage.exe: error: Most likely, the VirtualBox COM server is not running or
    failed to start.

    Help Please!!!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s