Networking with VirtualBox

Building Bridges

Linux has virtual network adapters in the form of TAP interfaces, and VirtualBox relies on this approach, too. The only requirements is free access to the /dev/net/tun device file for the user account used by VirtualBox.

Also, you need a bridge software, such as the bridge-utils package, and the tunctl command-line tool, which is part of the uml-utilities package on openSUSE.

Bridging with VirtualBox can be approached two possible ways on start up:

  • If you will always have a fixed number of guests, the correct approach would be to set up a permanent interface to which the virtual machine connects.
  • For a more flexible approach, you can let the virtual machine autonomously create a dynamic interface.

However, you need to type the administrative password in either case.

Permanent or Dynamic Interface

The list of commands for setting up a permanent interface is quite intimidating.

The first thing is to set up the bridge and connect it to eth0:

brctl addbr br0
ifconfig eth0
brctl addif br0 eth0

Updating the IP addresses comes next. If you use a DHCP server to assign addresses, dhclient br0 will handle this; if not, you need to assign addresses manually with ifconfig br0 IP address.

For each simulated network card in the guest system, you need a virtual interface host side; VBoxAddIF vbox0 User br0 connects it to the bridge.

The VBoxAddIF script creates a TAP interface, called vbox0, and grants the user User account to it. VBoxAddIF is included with the VirtualBox package, but hidden away in the depths of the source code directory tree in src/VBox/Installer/linux.

Final Step

The final step, working as root, is to connect the simulated card in the guest system with the TAP interface. To do so, you need to enter the card name as the Interface name in the configuration dialog. In this case, leave the two lines for scripts blank.

To release the interface again after use, type VBoxDeleteIF vbox0 at the command line. Incidentally, this tool is missing in the open source variant.

The second method involves running two scripts: one to create the TAP interface and connect it to the bridge and the other to disable the interface again.

Listing 1 shows a sample script based on one provided in the manual for enabling a TAP interface; the VirtualBox manual [3] provides more detailed information on this.

Listing 1

Enabling a TAP Interface


Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Virtual Box

    Many popular virtualization tools are either too expensive or too complicated. If you’re looking for another option, try the no-cost and user-friendly VirtualBox.

  • phpVirtualBox

    Putting all virtualization tasks on a separate server saves significant resources on the client. phpVirtualBox makes it possible to create, configure, manage, and use remote VMs in a browser window.

  • Virtual Windows 8.1 on Linux

    For occasional Windows users, a virtual machine is the ideal solution. But will Windows 8.1 work in VirtualBox and VMware?

  • Virtualizing Windows 8

    How does the latest Windows work in a virtual machine? We tried out Windows 8 as a guest system in vMware Workstation and virtualBox on Linux.

  • VirtualBox Introduces New Features, Some Experimental

    The free virtualization product VirtualBox has released a new version 2.1 that not only supports 3D graphics, but the full VMDK and VHD formats from VMware and Microsoft.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More