Mainfram Reality


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.

  1. #!/bin/shUSERNAME=user           # login name of HOST system
  2. DHCP=0      # set to 1 to use dynamic ip for bridge
  3. IP_ADDRESS=192.168.0.4    # static ip address of bridge (only used if DHCP set to 0)
  4. tunctl -t tap1 -u $USERNAME
  5. brctl addbr br0
  6. ifconfig eth0 0.0.0.0 promisc
  7. brctl addif br0 eth0
  8. if [ DHCP = 1 ]; then
  9.  dhclient br0
  10. else
  11.  ifconfig br0 $IP_ADDRESS
  12. fi
  13. brctl addif br0 tap1
  14. ifconfig tap1 up
  15. 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

3 Comments so far

  1. Jorge October 7th, 2008 8:32 pm

    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

  2. mainfram October 8th, 2008 7:41 am

    What you can do is add the gateway yourself.
    Add the following to the bottom of the script

    sudo route add default gw GATEWAYIP br0

    Also I updated to latest version of wicd and it seems to run the scripts now.

  3. Jorge October 8th, 2008 1:43 pm

    thanks mainfram.
    I added route definition as last line in script and now is working fine.
    Regards.
    Jorge

Leave a reply