Simple Network Setup On VirtualBox 2.1
I’ve been using linux-vserver for the past few years, but as there is no linux-vserver kernel for ubuntu and I don’t want to give my time re-compiling kernel, I’ve decided to try alternative virtualization 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 network properly on virtualbox-ose, i was a little bit disappointed. But as VirtualBox 2.1, they seem to fix lots of problems with network 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 network 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 bridge, 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 bridge-utils
$ sudo aptitude install bridge-utils
I add bridge interface br0
sudo brctl addbr br0Then I’ve configured my /etc/network/interfaces (at host machine)
auto br0
iface br0 inet static
address 192.168.5.1
netmask 255.255.255.0
bridge_maxwait 0
bridge_ports loPlease pay attention to bridge_ports line, I’ve used loop back device so the bridge 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 network and bring br0 up
$ sudo /etc/init.d/network restart
On Guest Machine
Before booting one of my debian 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/network/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 address 192.168.5.2 netmask 255.255.255.0
Restart the network
$ sudo /etc/init.d/network restart
On my other guest, I make the same and gave 192.168.5.3 as IP address.
At the end:
- All my guests can reach each other and the host in 192.168.5.0/24 network
- I do not need any special configuration on host boot.
- I have also a Windows XP guest which I configured the network on same basis and work flawlesly.
Good luck.


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?
@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.
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?
thanks
@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.