In order for this to run, you will most likely need a wired network connection, since most wireless-adapters won’t support bridged networking! This description is intended to be used with VirtualBox >= 1.4.0, since earlier versions handle the virtual networking differently due to kernel changes in 2.6.18 and later.
First of all, you’ll have to check the permissions on the device /dev/net/tun . The user running VirtualBox with bridged networking needs to have access to this device. The easiest way to do this is by chown’ing the group vboxusers to it:
sudo chown :vboxusers /dev/net/tun sudo chmod 0660 /dev/net/tun
You will also have to install the package bridge-utils and uml-utilities:
sudo apt-get install bridge-utils uml-utilities
Now we will create 2 scripts which are executed when the virtual machine starts/stops. I will create those scripts in my home dir. Here is the start script, I called it starttun.sh:
#!/bin/bash brctl addbr br0 ifconfig eth0 0.0.0.0 brctl addif br0 eth0 #if you have a dhcp-server uncomment this line: #dhclient3 br0 #If you have a static IP uncomment the following lines and
#change the IP accordingly to your subnet: #ifconfig br0 192.168.178.5 up #route add default gw 192.168.178.1 #Now we will create the tap device for the vm,!
# change your username accordingly tunctl -t tap0 -u simon #Now add the tap-device to the bridge: ifconfig tap0 up brctl addif br0 tap0
Now you’ll have to create the stop script, i called it stoptun.sh 😉
#!/bin/bash #bring the interfaces down ifconfig tap0 down ifconfig br0 down brctl delif br0 tap0 brctl delbr br0 #now setup your network-interface again #for dhcp uncomment the following line #dhclient3 eth0 #For a static IP uncomment the following lines and change them accordingly: #ifconfig eth0 192.168.178.5 #route add default gw 192.168.178.1 dev eth0
Finally you’ll have to make the scripts executable:
sudo chmod ug+x starttun.sh sudo chmod ug+x stoptun.sh
It’s time to set up VirtualBox to use the interface. For this go to the SetUp of your Virtual Machine under Network and tell VirtualBox to start/stop thescripts, when the VM is started/stopped. To do this, select “Host Interface” under Attached To. As Interface Name you use “tap0” and for the startscript you use:
For the stopscript accordingly:
Note: If you use KDE, you’ll have to use kdesu instead of gksudo