Thursday, 14 June 2012

How-to: VirtualBox Networking Part One - Adapters

This all started when I needed to run a sandboxed instance of Wordpress. The simple part was creating a virtual Ubuntu 11.10 server as a guest inside my VirtualBox host.

Then I discovered I knew much less about networking than I thought, a topic full of packets and switches and routing. I know much less about networking in VirtualBox, where all that stuff is virtualised in software.

Several attempts and a networking crash-course later, mission accomplished, and, to save you my pain, here's what I found.

VirtualBox network options
 Install any version of VirtualBox from 3.0 onwards and you'll find similar layouts and capabilities.

For any of your installed virtual machines, click on Settings > Network. This is the default view. Any virtual machine can have up to four network adapters which you can enable as needed. Most of the time, you'll need just one. Usually when you create a virtual machine you can leave VirtualBox to get on with creating a single network adapter allowing you to see out onto the Internet.

You might need multiple adapters of different types, or the same type with different settings, according to the use of your virtual machine and the networks - physical and virtual - to which it is connected.

For my virtual web-server running Wordpress, things get a bit more complex, so here we go...

The Adapter Type defines the virtual hardware available to your virtual machine. VirtualBox will do its best to mediate the virtual network card with whatever physical adapters you have on your host machine. Open the Advanced pane and you get additional options for setting up your network adapter. I'm going to run through the settings deliberately out of sequence, starting with the Adapter type.

VirtualBox will attempt to emulate some common types of network cards for which it has the drivers and protocols. PCnet-FAST III is the default selection, although I often select the Intel PRO/1000MT adapters if I'm looking for better compatibility with Intel hardware. There are two server versions for higher throughput if you intend your VM to run hot in a production environment. Desktop users needn't worry. If you have a problem with one of the Adapter types, you can try another, including a PCnet-FAST II for older machines.

Mode : the rather racy sounding 'Promiscuous Mode' has to do with the behaviour of the virtual switch used by Internal Networking, Bridged and Host Only. You can make a VM's network port accept traffic targeted for other virtual machines, or even the host, in addition to traffic addressed specifically to it. Promiscuous Mode is something 99% of users should never touch, and is there in cases where you need to diagnose the cause of certain network problems: end of.

MAC Address : short for Media Access Control, the MAC address is a hardware address that uniquely identifies each network resource or node of a network. It is a unique identifying number for a something that is usually hard coded into physical network adapters. VirtualBox generates the MAC addresses of virtual machine network cards.

There is a little button on the right to regenerate the MAC address; should you clone a virtual machine, it will need its own unique MAC to run on your virtual network alongside the original.

The Cable connected check-box does the same thing as plugging or unplugging a physical cable. This is the setting that connects your virtual network adapter to your virtual network. It is different from the top-most check-box for Enable Network Adapter, which allows you to effectively insert or pull the network adapter from the machine.

Finally, the Port Forwarding button opens another dialog allowing you to define the traffic rules for the adapter; how traffic of certain types is routed between host and guest. This applies only to certain network attachments which we will go on to look at next.

This is determined by the Attached to option (with it's little pal, the Name option), which is the sharp end of networking in VirtualBox and the thing that gave me most trouble at the start of my experiment.

We'll look at the different types of VirtualBox networking in the following parts of this series. RC

Image credit: Fiber Optic Lamp at Night by Alex Blackie