[HOW-TO] Bridge Network Interface in VirtualBox
When U install VirtualBox and need to connect to your Guest box with an IP in the same range that you using not the range that VirtuaBox (Which using DHCP and you Host box acts like the DHCP Server for the guest boxes different range and the actual IP of the guest box is the same of your host box ip).
If you have the same problem so this is the how to you looking for :D.
Let's Start First you have to install VirtualBox :p if u did not install it it's simple.
sudo apt-get install virtualboxNow let's go the real work :o :)
Step 1
You need to install "bridge tools" and "User-mode Linux (utility programs)"
sudo apt-get install uml-utilities bridge-utils
Step 2
Create a TAP Interface
sudo tunctl -t tap1 -u usernameand username is your username (eg. in my case it's bahaa)
so i should type
sudo tunctl -t tap1 -u bahaa
Step 3
Create the Bridge
sudo brctl addbr br0as br0 is the bridge interface name (you can name it as u like)
Step 4
You need to set your network interface in promisc mode "this means it's shared with all interfaces connected to it" in our case will be the bridge interface br0
sudo ifconfig eth0 0.0.0.0 promisc
Step 5
Now we will link our real interface eth0 to the bridge interface br0
sudo brctl addif br0 eth0
Step 6
Assign an IP to the br0. If you are using DHCP
sudo dhclient br0Or, if you assign an IP yourself
sudo ifconfig br0 192.168.0.100
Step 7
Link TAP to bridge br0
sudo brctl addif br0 tap1
Step 8
Activate TAP interface
sudo ifconfig tap1 up
Step 9
Add the default gateway to your bridge interface
sudo route add default gw 192.168.0.1 br0Where 192.168.0.1 is your gateway ip (eg. router ip in most cases).
Step 10
Change the permission of /dev/net/tun
sudo chmod 0666 /dev/net/tun
Step 11
At the VirtualBox startup panel, choose “Host Interface” and add “tap1″ to “Interface Name”.
Step 12
At the guest (after boot up the guest OS), change the IP of the guest OS to the same subnet of your host. this is example for
/etc/network/interfaces
iface eth0 inet static
address 192.168.0.101
netmask 255.255.255.0
gateway 192.168.0.1
network 192.168.0.0
dns-nameservers 208.67.222.222 208.67.220.220
Step 13
Now, you can connect to the guest OS by its IP in VirtualBox.
When you reboot your guest OS, you need to repeat the Step 2 to 10 to Again. Or, you can create a executable script to make your job easy.
Have fun :D
BTW I'm using this way and it works with me in Ubuntu 9.04.
Reference
- Printer-friendly version
- Login or register to post comments
- 1624 reads


No longer need this
Salam,
I'm using VBOX version 3.0.2 and with this version, you don't need all these commands as they already fixed this problem a few months ago.
Just install the latest version from virtualbox.org and it'll work perfect with you.
salam