07
Nov
2007

How to setup a bridge between a virtual machine with VirtualBox and a Fedora host

Hi everybody, I will try to show you how it's easy to configure your virtual machine to be visible on the network, like another machine.

First, you need to install the bridge-utils package

yum install bridge-utils
and you need to create a bridge.
Go to /etc/sysconfig/network-scripts/ and create a new file (ifcfg-tap0 for example) :

vi /etc/sysconfig/network-script/ifcfg-tap0

IMPORTANT NOTE : NetworkManager load the scripts files in alphabetical order. If you set the name of your bridge with the first letter is before the first letter of your interface, it will not work ! (br0 connected to eth0 for example). Take care about that !

Put these lines :

DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static #or dhcp, and leave the next
IPADDR=192.168.0.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
BROADCAST=192.168.0.255
then open your network configuration file (for example ifcfg-eth0) and add these lines (if they didn't exists) :

PEERDNS=no
TYPE=Ethernet
USERCTL=yes
IPV6INIT=yes
BRIDGE=tap0
Restart the network service by

su -lc 'service network restart'
Finally, and the most important, in root, you need to specify the bridge for VirtualBox with this command :

VBoxAddIf vbox0 {user} tap0

With {user} your current user, br0 the name of your bridge, and vbox0, it's the name of the network you will need to specify in the preferences of VirtualBox, network section. Select Host Network Adaptater, and specify vbox0.

Voilà ! You can launch your virtual machine in bridge mode ! :)

(See : http://forums.fedora-fr.org/viewtopic.php?pid=200600 for more info (in french))

You can have some issues after a reboot, with your virtual machine that cannot connect to the web. If it happens, stop your vm, remove the interface and re-add it to virtualbox (in root mode) and start your vm.


# Command to remove an interface :
VBoxDeleteIF vbox0

# And now, we add it:
VBoxAddIF vbox0  tap0