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
16 Replies to “setting up a bridged network for virtualbox on ubuntu linux (Host Interface)”
Thanks ! You Saved my day !
Hey I was wondering if you could possibly make the script one script and have it call gksudo/kdesu so that you can have Virtualbox run the command from the ‘Network’ settings of the VM.
The scripts are intended to be used by Virtualbox this way. You can set the above commands for start/stop in the according VM-Settings under Network.
How would I configure a bridge to have a VirtualBox guest in a network with the host, and VMware’s vmnet1 interface? vmnet1 is VMware’s host only network, where the guest machines are in a private network, and the host is part of that network. (So guests can see eachother, can see the host, but can not see anything outside the host, like the internet.)
I love the script.You sir are a legend.
I tried working your way but I must have messed up somehow.
Here is the script that I used. Can you please help me use eth0 with multiple taps!
echo “Restarting VirtualBox Host Interfaces”
echo “All virtual connections will be lost”
ifconfig tap1 down
ifconfig br0 down
brctl delbr br0
ifconfig eth0 172.16.31.150 netmask 255.255.255.0 up
route add default gw 172.16.31.1 eth0
echo “Bringing down VirtualBox Host Interfaces”
tunctl -t tap1 -u dofta
chown root.vboxusers /dev/net/tun
chmod g+rw /dev/net/tun
brctl addbr br0
ifconfig eth0 0.0.0.0 promisc
brctl addif br0 eth0
ifconfig br0 172.16.31.150 netmask 255.255.255.0
route add default gw 172.16.31.1 br0
brctl addif br0 tap1
ifconfig tap1 up
echo “VirtualBox Host Interfaces Bridged Successfully”
I’m looking for this answer on my own, but I’d like some help resolving it.
I need this to work for an end user, the fewer things they have to do the better. How do I run these scripts without gksudo? I’m not so concerned about security (I know call me crazy) but I can’t have my users entering passwords all the time.
Any help I appreciate. If I find the answer I’ll share it here.
Appreciate the effort and answers but ….
this is exactly the type of thing that will keep linux/ubuntu from ever achieving a significant portion of the mqarket. As long as users have to spend a day searching and patching every application that was not built into the OS distribution then the OS will never make it to the mainstream and it will remain in the realm of hakers, nerds and others that have more time than money.
I appreciate the info & i’m early in solving the problem here but under Ubuntu 8.10 and Virtualbox 2.0.4_OSE, this FAILS. The error is as follows when the VM executes:
Failed to initialize Host Interface Networking.
VBox status code: -3100 (VERR_HOSTIF_INIT_FAILED).
Again 0 another “it worked on mine…” kind of answer. If I get it working, I’ll post it but I have to agree with the individual who said this prevents Ubuntu from succeeding by having to patch every little thing. That’s kind of the overall Linux problem succintly stated. The problem is it takes so $&@)*&# long to get everything working. God forbid, a kernel update comes out – you’re at it all over again. (sorry – just ranting at yet another linux FAILURE)
If anyone has solved this problem, please share & save me the time that I truly need to devote elsewhere…
I have the same problem as “rshane” has.
Does anybody solved this? If yes, can you please post it? thank you.
My guess would be, that there is something wrong with the permissions on the file /dev/net/tun . Did you change the permissions like explained above in the first step? And are you a member of the group vboxusers? Remember also, that if you just made your user a member of that group, you have to log out and then log in again for the changes to take effect!
Excellent, this is whta I was looking for
I got stuck on the following:
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:
I cannot see Host Interface, could you give more details?
On Virtualbox 2.2.4, there is no “Host Interface” under “Attached to”; only “Bridged Adaptor” and “Host Only Adaptor”. Neither is it possible to run scripts. An update would be very useful.
It looks like if you select “Bridged Adapter” as attached to and select eth0 that it will work. It worked for me anyway allowing me to join my domain.