To configure bridging, you basically go through three steps on the host machine. First you need to create a bridge. Next you create virtual interface(s). Then you add a real interface and virtual interface(s) to the bridge. Because of the scripts available on the distribution which take care of all the details, all of this sums up to two steps:
Edit the host machine's /etc/network/interfaces to let your system know what the tap device is. Note: This step will be saved permanently to your host machine's settings so that even if you reboot the machine, you won't need to repeat it.
sudo cp /etc/network/interfaces /etc/network/interfaces.`date +~%b-%d-%Y~%T`
gksudo gedit /etc/network/interfaces
kdesu kate /etc/network/interfaces
auto tap1 iface tap1 inet manual up ifconfig $iface 0.0.0.0 up down ifconfig $iface down tunctl_user USERNAME
sudo tunctl -t tap1 -u USERNAME sudo chown root.vboxusers /dev/net/tun sudo chmod g+rw /dev/net/tun
KERNEL=="tun", NAME="net/%k", GROUP="vboxusers", MODE="0660"
sudo brctl addbr br0
Put your current interface (in this case eth0) into promiscuous mode, then add it to the bridge and give the bridge a DHCP address. Note after running the following ifconfig command via ssh you may/will lose connectivity to the box. I'm thinking that using the auto script instead, which is later on in this document, will be required for creating the tunnels.
sudo ifconfig eth0 0.0.0.0 promisc sudo brctl addif br0 eth0
sudo dhclient br0
#Where 192.168.1.105 is your host machine's static IP and 255.255.0.0 is your netmask sudo ifconfig br0 192.168.1.105 netmask 255.255.0.0 #Where 192.168.1.1 is your default gateway sudo route add default gw 192.168.1.1 br0
Add the new tap1 device to the bridge and activate tap1 (the second line appears to be necessary according to http://ubuntuforums.org/showthread.php?t=561461#3)
sudo brctl addif br0 tap1 sudo ifconfig tap1 up
You should now be able to use host networking in VirtualBox. Just change "Attached to" from "Nat" to "Host interface" and type "tap1" (without the quotes) into the Interface Name box in your virtual machine's Networking settings. Read the manual as well. There are some other nifty ways to do this. Do not forget to use the root account when doing this. Also, reboot your computer afterwards.
Since the steps in the "Create A Bridge" section are not permanent, if you reboot the machine, you'll have to repeat them (with the exception of the part where you can edit /etc/udev/rules.d/20-names.rules). Rather than re-entering all this information manually, you can automate it by saving the commands into text files and executing them either via a shortcut or from the command line.
Below are four scripts. You'll need either the two static IP scripts or the two dynamic IP scripts, depending on whether your host computer uses a static or dynamic IP. Paste the contents of each into a text editor and save the file. I recommend naming them BridgeUp and BridgeDown or something similar so that you'll know at a glance what each one does.
If you want to make them executable, open the properties of each file and change the executable setting. Then you can either click the files to launch them or make shortcuts to them and click the shortcuts.
sudo tunctl -t tap1 -u USERNAME sudo chown root.vboxusers /dev/net/tun sudo chmod g+rw /dev/net/tun sudo brctl addbr br0 sudo ifconfig eth0 0.0.0.0 promisc sudo brctl addif br0 eth0 sudo ifconfig br0 HOST_IP netmask NETMASK sudo route add default gw GATEWAY br0 sudo brctl addif br0 tap1 sudo ifconfig tap1 up
sudo tunctl -t tap1 -u USERNAME sudo chown root.vboxusers /dev/net/tun sudo chmod g+rw /dev/net/tun sudo brctl addbr br0 sudo ifconfig eth0 0.0.0.0 promisc sudo brctl addif br0 eth0 sudo dhclient br0 sudo brctl addif br0 tap1 sudo ifconfig tap1 up
sudo ifconfig tap1 down sudo ifconfig br0 down sudo brctl delbr br0 sudo ifconfig eth0 HOST_IP netmask NETMASK up sudo route add default gw GATEWAY eth0
auto tap2 iface tap2 inet manual up ifconfig $iface 0.0.0.0 up down ifconfig $iface down tunctl_user USERNAME