Dummy Information Store

29 Mar

Simple Network Setup On VirtualBox 2.1

I’ve been using linux-vserver for the past few years, but as there is no -vserver kernel for and I don’t want to give my time re-compiling kernel, I’ve decided to try alternative solutions. I’ve already tried qemu, vmware but i really don’t like them. So I gave a shot to VirtualBox.

After trying and seeing the mess on setting up properly on -ose, i was a little bit disappointed. But as 2.1, they seem to fix lots of problems with utilization.

Here is my status;

  • I’ve using 64bit Ubuntu Intrepid Ibex on my Thinkpad T61P with 4GB memory
  • I’m using my notebook both at work and home, and some other places off course
  • At work, I use wired and wireless connection (eth0) but at home I’m using wireless (ath0)
  • So there is always different setups at home, office, etc.
  • All my running guests and the host should be able to communicate each other.

So I need static IP utilization on all guests and the host, and all of my guests should access to internet, and all my guests should isolated from lan. So I tried host interface and

  • When I use eth0 to , my guests was not reachable at home because eth0 link is not used.
  • When I use ath0, there was another problem which I don’t remember now :)
  • On both interfaces, my guests were not isolated, and could be reached from lan.

And here is my solution:

On host machine

First I’ve installed -utils

$ sudo aptitude install bridge-utils

I add interface br0

sudo brctl addbr br0

Then I’ve configured my /etc//interfaces (at host machine)

auto br0
iface br0 inet static
	bridge_maxwait 0
	bridge_ports lo

Please pay attention to bridge_ports line, I’ve used loop back device so the will be isolated from my lan, and using eth0 or ath0 or anything else will not make any difference as loop back interfaces is will always stay there.

Finally I’ve restart my and bring br0 up

$ sudo /etc/init.d/network restart

On Guest Machine

Before booting one of my guest, I’ve added two interfaces.

  • First Interface, which the guest uses to reach to lan:
    • Adapter Type: PCNet-Fast III
    • Attached to: NAT
  • Second Interface, which the guests communicate each other and the host
    • Adapter Type: PCNet-Fast III
    • Attached To: Host Interface
    • Host Interface: br0

Then I’ve booted my guest, enter the GUI and edit /etc//interfaces file

auto eth0 #This is the NAT'ed interface
iface eth0 inet dhcp
auto eth1 #This is the bridged interface
iface eth1 inet static

Restart the

$ sudo /etc/init.d/network restart

On my other guest, I make the same and gave as IP address.

At the end:

  • All my guests can reach each other and the host in
  • I do not need any special configuration on host boot.
  • I have also a Windows XP guest which I configured the on same basis and work flawlesly.

Good luck.

4 Responses to “Simple Network Setup On VirtualBox 2.1”

  1. By Onur YALAZI on Mar 29, 2009 | Reply

    What if I would like to have a local area network bridge? I mean to the corparate or to my home network?
    Will adding another bridge_port like ath0 do the magic?

  2. By Emre Odabas on Mar 30, 2009 | Reply

    @yalazi: infact if you want to connect to lan directly, just select eth0/ath0 as your host interface on virtualbox guest settings. you don’t need a bridge at all.

    I’m using a bridge interface as its link is assumed ready all the time and i’m carrying my notebook with me, plugging to different network infrastructures. on a desktop or server environment you should not need any bridge interface to connect your lan.

  3. By bahram (from iran) on May 1, 2009 | Reply

    hi, i use mint(6) kde as host and windows xp as guest and did your metod. when i do this :
    sudo /etc/init.d/networking restart , on command line, the result was this:
    bahram@batman ~ $ sudo /etc/init.d/networking restart
    * Reconfiguring network interfaces…device lo is not a slave of br0
    can’t add lo to bridge br0: Invalid argument
    [ OK ]
    bahram@batman ~ $
    whats wrong?

  4. By Emre Odabas on May 4, 2009 | Reply

    @bahram: infact, bridging to lo is a simple fake, if you had problems with it;

    * you may create a tap interface and bridge to it,
    * or simply remove the “bridge_ports lo” line from your configuration, as it’s not really necessary to add an interface to this bridge in a setup like this.

    or just upgrade to VirtualBox-2.2 as it has a new interface mode “Host-Only Interface”, which serves to exactly same purpose.

Post a Comment