The wikis are now using the new authentication system.
If you did not migrate your account yet, visit https://idp-portal-info.suse.com/

Virtualbox Network Bridging

Jump to: navigation, search

Susemini.png 本文处于需要翻译的文章的状态,欢迎您积极参与翻译与修订。 翻译人员:无,修订人员:无。

Bridging for VirtualBox

Tested on:

  • OpenSuSE 10.3 + VirtualBox-1.6.2_31466_openSUSE103-1
  • OpenSuSE 11 + VirtualBox 2

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'
STARTMODE='auto'
NAME='100 MBit 3Com 3c905 [Boomerang]'
USERCONTROL='no'
### 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:

 # ifup br0
 # /etc/rc.d/network restart

Check the new configuration of the network devices

 # /sbin/ip addr

you should see at least four network interface, with output look like these,

lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
eth0: <LOOPBACK,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
eth1: <LOOPBACK,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
br0: <LOOPBACK,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN

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/24 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/27
  • Gateway  : 10.2.26.225
  • Proxy  : 10.1.10.17
  • Guest IP address  : 10.2.26.249/27

Big step :

  1. Disable interface 'eth0'.
  2. Remove IP address of 'eth0'
  3. Create bridge interface 'br0' and set IP address and netmask of 'br0' to the value of IP address and prefix length of 'eth0'
  4. Create virtual network card 'tap0' with VBoxAddIF and add 'tap0' to bridge 'br0'.
  5. Add 'eth0' to 'br0'.
  6. Bring all interfaces up.

Detailed step,

  • Disable interface 'eth0'.
 # /sbin/ip link set eth0 down
  • Remove IP address of 'eth0'
 # /sbin/ip addr flush dev eth0
To change the interface address to permanent, edit file '/etc/sysconfig/network/ifcfg-eth0' and comment IPADDR config and add LINK_OPTIONS.
Example of configuration :
BOOTPROTO='static'
STARTMODE='ifplugd'
IFPLUGD_PRIORITY='1'
#IPADDR='10.2.26.248/27'
NAME='Hewlett-Packard Company Presario V6133CL'
USERCONTROL='no'
  • 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/ip addr add 10.2.26.248/27 dev br0
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'
NAME='bridge for vbox'
BRIDGE='yes'
BRIDGE_PORTS='eth0 tap0'
BRIDGE_FORWARDDELAY='0'
  • Create virtual network card 'tap0' with VBoxAddIF and add 'tap0' to bridge 'br0'.
This will create permanent virtual network card,
 # /usr/bin/VBoxAddIF tap0 johndoe br0
  • Add 'eth0' to 'br0'.
 # /sbin/brctl addif br0 eth0
  • Bring all interface up.
 # /sbin/ip link set tap0 up
 # /sbin/ip link set eth0 up
 # /sbin/ip link set br0 up
  • Last check, run
 # /sbin/ip addr
and make sure all interface are UP (see Scenario I).
Caution

Doing as set out above, I was not able to get this to work using openSUSE 11.0 and VirtualBox 2.0.4. I then tried to revert to my previous setup, and discovered my network configuration was hosed.... network restart, reconfiguring the network, etc. did not help. It seemed the dhcp client daemon was not getting called after the eth0 was up. I ended up reinstalling the dhcp, dhcp client + daemon, avahi, and ipw-firmware packages. Then I was back on line. The above recipe deviates from the VirtualBox 2.0.4 documentation..... If I ever get this working I will clarify what was done and describe how to reset your setup.

Within VirtualBox

Now set your VirtualBox machine to use the "Host Interface" tap0 in configuration menu "Network" >> "Host Interface Settings" >> "Interface Name". In VirtualBox 2.0, there are the options "Setup Application" and "Terminate Application". Leave them empty!

Run your virtual machine box set their network address and voila! ;) you have two machine connect to the internet.