Ubuntu, Sun VirtualBox and bridged networking
I am running VirtualBox on my laptop (host OS is Ubuntu Hardy). Currently I use VirtualBox to run a Windows Vista Ultimate guest OS (for all those times when I need windows).
One annoying thing about VirtualBox is that it does not give you an easy way to setup a network bridge like vmware does. So after digging around the web I found the following script does the job nicely.
-
#!/bin/shUSERNAME=user # login name of HOST system
-
DHCP=0 # set to 1 to use dynamic ip for bridge
-
IP_ADDRESS=192.168.0.4 # static ip address of bridge (only used if DHCP set to 0)
-
tunctl -t tap1 -u $USERNAME
-
brctl addbr br0
-
ifconfig eth0 0.0.0.0 promisc
-
brctl addif br0 eth0
-
if [ DHCP = 1 ]; then
-
dhclient br0
-
else
-
ifconfig br0 $IP_ADDRESS
-
fi
-
brctl addif br0 tap1
-
ifconfig tap1 up
-
chmod 0666 /dev/net/tun
This script must be run with elevated privileges (sudo). Since I connect to different networks at home and at work (home uses static IP, work uses DHCP), I created two scripts, one for home and one for work. Within Ubuntu I use wicd as my network manager and it has the ability to run scripts before/after connect, etc… but I can’t seem to get it to execute the above script automatically when I pick a profile, so for now I have to run the script manually.
3 Comments so far
Leave a reply

Hi
I’m using wicd too as network manager and i ran the script but after this i lost my default gateway then i can’t to navigate by internet. Only i can ping to devices connected to my local network.-
I reconfigured wicd replacing eth0 by br0 as wired interface but problem persist.-
Can you help me ?
TIA .-
Regards .-
Jorge
What you can do is add the gateway yourself.
Add the following to the bottom of the script
sudo route add default gw GATEWAYIP br0Also I updated to latest version of wicd and it seems to run the scripts now.
thanks mainfram.
I added route definition as last line in script and now is working fine.
Regards.
Jorge