Virtualbox Network Bridging
From openSUSE
Contents |
Bridging for VirtualBox
Tested on,
- OpenSuSE 10.3 + VirtualBox-1.6.2_31466_openSUSE103-1
Software Prerequisites
- bridge utilities (package name : bridge-utils)
- user mode linux utilities (package name : uml-utilities)
You can search the software packages here http://packages.opensuse-community.org/
Basics of Bridging in OpenSuSE 10.3
See Bridging for more background.
The OpenSuSE firewall can interfere with bridging. Be sure to take care of this to ensure that it is not the firewall that is interfering with your bridge connection. If you are not sure, try to turn off the firewall before create the bridge connection. If connection has been made up and both host and guest machine connected, try to turn on the firewall again and see how the connection again.
To turn off firewall:
# /sbin/rcSuSEfirewall2 stop
and to turn the firewall on again:
# /sbin/rcSuSEfirewall2 start
The information in each of the ifcfg-*** files is described in the SLED documentation and documented in the template file included in your OpenSuSE distribution, see:
/etc/sysconfig/network/ifcfg.template
System Scenario for Illustration
Scenario I : Bridging With Two Network Card
Take the following system as an example:
- DSL modem (into router)
- LinkSys router (as gateway 192.168.1.1 with DHCP capabilities)
- Desktop system/server running OpenSuse 10.3 (static IP 192.168.1.2)
- eth0 (Marvell 88E8001 Asus on-board ethernet, intended as the "main"
- connection for the host OS)
- eth1 (3Com 3c905 PCI ethernet - intended for the bridge)
As 'root' edit/create the files below or configure them based on your network requirement or topology, in this illustration the configuration will be look like these,
### file: /etc/sysconfig/network/ifcfg-eth0 BOOTPROTO='static' IPADDR='192.168.1.2/24' STARTMODE='auto' NAME='1000 GBit Marvell 88E8001 (Asus)' USERCONTROL='no'
### file: /etc/sysconfig/network/ifcfg-eth1 BOOTPROTO='static' IPADDR='0.0.0.0' STARTMODE='auto' NAME='100 MBit 3Com 3c905 [Boomerang]' USERCONTROL='no' NETMASK='255.255.255.0'
### file: /etc/sysconfig/network/ifcfg-br0 STARTMODE='auto' BOOTPROTO='dhcp' USERCONTROL='no' BRIDGE='yes' BRIDGE_PORTS='eth0 eth1' BRIDGE_AGEINGTIME='20' BRIDGE_FORWARDDELAY='0' BRIDGE_HELLOTIME='2' BRIDGE_MAXAGE='20' BRIDGE_PATHCOSTS='3' BRIDGE_STP='on'
Then, run these command to test the configuration:
# /etc/rc.d/network restart
Check the new configuration of the network devices
# /sbin/ifconfig
you should see at least four network interface, with output look like these,
br0 [skip]
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
[skip]
eth0 [skip]
inet addr: 192.168.1.2 [skip]
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
[skip]
lo [skip]
eth1 [skip]
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
[skip]
The point here is to make sure all interface that you need for bridge is UP.
Now set your VirtualBox machine to use eth1 in configuration menu "Network" >> "Host Interface Settings" >> "Interface Name".
After virtual machine is up, set guest IP address to 192.168.1.3 and netmask to 255.255.255.0 and gateway to 192.168.1.1.
Scenario II : Bridging With One Network Card and One Virtual Network card
Result of this scenario is,
- Host and guest machine can communicate,
- Guest can connect to other machine in LAN and internet and vice versa.
Take the following system as an example:
- User name of host machine : johndoe
- Host Machine with 'eth0' : 10.2.26.248 netmask 255.255.255.224
- Gateway : 10.2.26.225
- Proxy : 10.1.10.17
- Guest IP address : 10.2.26.249 netmask 255.255.255.224
Big step :
- Turn down interface 'eth0'.
- Set IP address of 'eth0' to 0.0.0.0 and with 'promisc' mode.
- Create bridge interface 'br0' and set IP address and netmask of 'br0' to the value of IP address and netmask 'eth0' before we set it to 0.0.0.0.
- Create virtual network card 'vbox0' with VBoxAddIF and add 'vbox0' to bridge 'br0'.
- Do not forget to set 'vbox0' to 'promisc' mode too.
- Add 'eth0' to 'br0'.
- Bring all interface up.
Detailed step,
- Turn down interface 'eth0'.
# /sbin/ifconfig eth0 down
- Set IP address of 'eth0' to 0.0.0.0 and with 'promisc' mode.
# /sbin/ifconfig eth0 0.0.0.0 promisc
- To change the interface address to permanent, edit file '/etc/sysconfig/network/ifcfg-eth0' and comment IPADDR and NETMASK config and add LINK_OPTIONS.
- Example of configuration :
BOOTPROTO='static' STARTMODE='ifplugd' IFPLUGD_PRIORITY='1' #IPADDR='10.2.26.248' #NETMASK='255.255.255.224' NAME='Hewlett-Packard Company Presario V6133CL' USERCONTROL='no' LINK_OPTIONS='promisc on'
- Create bridge interface 'br0' and set their IP address.
- To create temporary bridge interface (the interface will be gone if the computer is restarted) :
# /sbin/brctl addbr br0 # /sbin/ifconfig br0 10.2.26.248 netmask 255.255.255.224
- To create permanent interface, go to /etc/sysconfig/network, create a file with name is 'ifcfg-br0' and content is:
BOOTPROTO='static' STARTMODE='auto' IPADDR='10.2.26.248/27' NETMASK='255.255.255.224' NAME='bridge for vbox' BRIDGE='yes' BRIDGE_PORTS='eth0 vbox0' BRIDGE_FORWARDDELAY='0'
- Create virtual network card 'vbox0' with VBoxAddIF and add 'vbox0' to bridge 'br0'.
- This will create permanent virtual network card,
# /usr/bin/VBoxAddIF vbox0 johndoe br0
- Do not forget to set 'vbox0' to 'promisc' mode too.
# /sbin/ifconfig vbox0 promisc
- Add 'eth0' to 'br0'.
# /sbin/brctl addif br0 eth0
- Bring all interface up.
# /sbin/ifconfig vbox0 up # /sbin/ifconfig eth0 up # /sbin/ifconfig br0 up
- Last check, run
# /sbin/ifconfig
- and make sure all interface is UP (see Scenario I).
Now set your VirtualBox machine to use vbox0 in configuration menu "Network" >> "Host Interface Settings" >> "Interface Name".
Run your virtual machine box set their network address and voila! ;) you have two machine connect to the internet.

