Linux : Configuring a network bridge for your Virtual Machines
stephane
My new center of interest those days being virtualization, I tried quite a few software starting with Xen, then QEMU, then KVM, and finally VirtualBox. But as far as giving a network access to the VM is concerned, I’ve always sticked to a network bridge for the reason that this makes the VM appear on the network just like any other computer of your network.
This post provided a sample script to setup a bridge suitable to use with all of the named virtualization softwares.
Here is the script I use for setting up the networking of a VM :
#! /bin/sh
# creating tap0 (a TAP device) and setting owner as the non-privileged user who
# will run VirtualBox
tunctl -u kattoo
# creating the bridge
brctl addbr br0
# stopping the initial networking
/etc/init.d/net.eth0 stop
# bringing up physical and virtual network interfaces
ifconfig tap0 up
ifconfig eth0 up
ifconfig br0 up
# connecting the TAP device and the physical NIC onto the bridge
brctl addif br0 tap0
brctl addif br0 eth0
# starting the bridge
/etc/init.d/net.br0 start
As you can see, this is pretty simple and straightforward, and there is much room for improvement 😉
A TAP device is a level 2 (think ethernet) virtual network interface which has one side connected to a process (in our case this will be VirtualBox or any other virtualization software such as Xen, QEMU, KVM …) and the other side is connected to the hosting Linux Kernel. In our case that end will be plugged in the network bridge so that every packet entering the bridge will be forwarded to the VM as well (and the other way round too).
This example is made with Gentoo Linux in mind, so you may have to adapt a bit for your own Linux distribution.
If you use VirtualBox, you can then set the network parameters for your VM as follow :
Should you have any question or improvement to suggest, feel free to hit the comments !