How to setup VirtualBox bridge mode on the fedora 9

Discussions related to using VirtualBox on Linux hosts.
Post Reply
magicwu
Posts: 3
Joined: 5. Jun 2008, 06:12

How to setup VirtualBox bridge mode on the fedora 9

Post by magicwu »

Dear All:
I try to use manual setup bridge mode on the fedora 9. It don't work. I check all value in my fedora 9 that is same manual suggust setting. It still not work. Who can tell me how to do? Thank you!

Sam!! :(
big2all
Posts: 5
Joined: 5. Jun 2008, 03:30

Post by big2all »

IN cent os 5.1 ( means Redhat entrprise linux 5.1, Virtual box ( personal) 1.6 rpm i am using ) i am able to use host network.

Steps followed by me :

First you need to modify vboxnet script
===========================
vi /etc/init.d/vboxnet

Around line 198 you'll see

while [ $i -le 10 ]; do
ifconfig "$1" up 2> /dev/null
if ifconfig | grep "$1" > /dev/null; then

Between the ifconfig "$1" line and the if ifconfig |grep "$1" line, insert a command to sleep for .5 seconds. So, it should now look like

while [ $i -le 10 ]; do
ifconfig "$1" up 2> /dev/null
sleep .5
if ifconfig | grep "$1" > /dev/null; then
""

1. vi /etc/rc.local add following lines at end of line
/bin/chmod 0666 /dev/net/tun
/bin/chmod 777 /dev/vboxdr

2.usermod -G vboxusers <userid> ( your yourname under you are running Virtualbox)

3.install bridge utils you can using yum

My network is 192.168.1.x / 255.255.255.0 with gateway 192.168.1.1 ( check yours )

4.vi /etc/sysconfig/network-scripts/ifcfg-eth0 add following entries

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
DHCP_HOSTNAME=rhel32bit.linux
TYPE=Ethernet
USERCTL=yes
IPV6INIT=no
PEERDNS=no
BRIDGE=br0

5.vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
IPADDR=192.168.1.33
NETMASK=255.255.255.0
GATEWAY=192.168.1.1


6.service network restart


7.VBoxAddIF vbox0 <user> br0 ( user is username under vritualbox runs )


it will creat tap interface vbox0

use this in your guest os network setting.

( in case if you are using Virtual box - 1.6 - for windows xp guest use intel card as virtual card )


SO here is in one shell script which will do hostnetwork [ you need to undo all chages what you did as per my first post ( vbox0)


---------------------------------

[root@rhel32bit opt]# cat vboxhostnetowrk.sh [static ip - you can dhcp as mentioned above ]
#!/bin/sh
PATH=$PATH:/sbin:/usr/sbin
brctl addbr br0
ifconfig eth0
ifconfig eth0 0.0.0.0
brctl addif br0 eth0
ifconfig br0 192.168.1.33 netmask 255.255.255.0 up
route add -net 192.168.1.0 netmask 255.255.255.0 br0
route add default gw 192.168.1.1 br0
VBoxTunctl -b -u root

ifconfig tap0 up
brctl addif br0 tap0

-Rav
Last edited by big2all on 5. Jun 2008, 09:16, edited 1 time in total.
magicwu
Posts: 3
Joined: 5. Jun 2008, 06:12

Post by magicwu »

First thank you help.

I use same method to try again, but it still not work. I have a setting difference with your. My BOOTPROTO=dhcp in the ifcfg-br0 file.
Have others worry for me?

Sam
big2all wrote:IN cent os 5.1 ( means Redhat entrprise linux 5.1, Virtual box ( personal) 1.6 rpm i am using ) i am able to use host network.

Steps followed by me :

First you need to modify vboxnet script
===========================
vi /etc/init.d/vboxnet

Around line 198 you'll see

while [ $i -le 10 ]; do
ifconfig "$1" up 2> /dev/null
if ifconfig | grep "$1" > /dev/null; then

Between the ifconfig "$1" line and the if ifconfig |grep "$1" line, insert a command to sleep for .5 seconds. So, it should now look like

while [ $i -le 10 ]; do
ifconfig "$1" up 2> /dev/null
sleep .5
if ifconfig | grep "$1" > /dev/null; then
""

1. vi /etc/rc.local add following lines at end of line
/bin/chmod 0666 /dev/net/tun
/bin/chmod 777 /dev/vboxdr

2.usermod -G vboxusers <userid> ( your yourname under you are running Virtualbox)

3.install bridge utils you can using yum

My network is 192.168.1.x / 255.255.255.0 with gateway 192.168.1.1 ( check yours )

4.vi /etc/sysconfig/network-scripts/ifcfg-eth0 add following entries

DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
DHCP_HOSTNAME=rhel32bit.linux
TYPE=Ethernet
USERCTL=yes
IPV6INIT=no
PEERDNS=no
BRIDGE=br0

5.vi /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
IPADDR=192.168.1.33
NETMASK=255.255.255.0
GATEWAY=192.168.1.1


6.service network restart


7.VBoxAddIF vbox0 <user> br0 ( user is username under vritualbox runs )


it will creat tap interface vbox0

use this in your guest os network setting.

( in case if you are using Virtual box - 1.6 - for windows xp guest use intel card as virtual card )

-Rav
big2all
Posts: 5
Joined: 5. Jun 2008, 03:30

Post by big2all »

Another method worked for me is ( i am pasting mail i got from some user):

--------------------------------------------------------

Wired Networks
This first method is for a wired network. For wireless bridged networking see below. My own network is behind a Linksys router which also gives out DHCP addresses. I use the default subnet of 192.168.1.0 with a netmask of 255.255.255.0. While I've been doing this on Fedora hosts, it should work with any Linux distribution. You will have to adjust addresses to your own network's layout.

In short, we'll create a bridge, bring down the ethernet interface, add it as a member of the bridge, bring the bridge up, create a tap interface, add that to the bridge as well, and we'll be more or less good to go. Before beginning make sure that you have bridge-utils (your distribution might call it something else) installed. Also, you'll have to either be root or have root privileges with sudo to perform many of these commands.

Lastly, most of these commands, on Fedora, are found in /usr/sbin or /sbin. In Fedora, those two directories are not in the $PATH of the normal user. There are various ways around this. In Fedora, you can first do su - (note the - after the su and space) which will give you root's environment, including the $PATH. Another way is to, before starting the series of commands, temporarily add those two directories to your $PATH. That can be done by typing

PATH=$PATH:/sbin:/usr/sbin

That segues nicely into my next comment. The User Guide's directions for Fedora won't work unless you have /sbin and /usr/sbin in your $PATH when you first log on or do an su -. The VBoxAddIF command that they discuss calls, among other things, ifconfig, which is in /sbin. Therefore, if you run it as a user with sudo, or do an su without the - afterwards, you'll get errors that ifconfig wasn't found. However, we're not going to do it their way. :).

We are going to create some temporary interfaces. If you have VirtualBox running all the time, you probably want to look at the User Guide's instructions. So, let's begin.

First create a bridge

brctl addbr br0

Now bring down the interface that you're using, in most cases, eth0. If you get your address through DHCP, you don't have to make note of your current settings. If you manually configure your ethernet card, then make sure you know its settings before doing this. You can find that out with

ifconfig eth0

For this example, we'll say that my settings are 192.168.1.55 for the address, with a netmask of 255.255.255.0. Such an address indicates that my network is a 192.168.1.0 network with a mask of 255.255.255.0. You can usually check this with route -n or netstat -r. It should show, among other things, something like

Destination Gateway Genmask Iface
192.168.1.0 * 255.255.255.0 eth0
default 192.168.1.1 0.0.0.0 eth0

(I've left some things out of the actual output, what I have above is what you want to notice. The Destination is the network, the Genmask the network's netmask and the line that begins default, with an address under the Gateway column is, oddly enough, your default gateway. If your card is manually configured, you'll need that information in a few minutes. Once you have the information (again, unnecessary if you get your address through DHCP) we can bring down the network card.

Note that this will temporarily disconnect you from the network, so you can't do this remotely.

ifconfig eth0 0.0.0.0

Next we add interface eth0 to the bridge

brctl addif br0 eth0

Now we can bring up the bridge. If you use DHCP, then simply run

dhclient br0

It should get an address. (If you get an error that dhclient is already running, then first kill it with pkill dhclient and try again. Some systems use dhcpcd rather than dhclient, adjust accordingly.)

If you had to manually set your address on eth0, then we'll do that on br0. In my example, say that I saw my IP address was 192.168.1.55. I'll give the bridge that address.

ifconfig br0 192.168.1.55 netmask 255.255.255.0 up
route add -net 192.168.1.0 netmask 255.255.255.0 br0

route add default gw 192.168.1.1 br0

Remember, we got those settings from route -n or netstat -r. Now that your bridge is up and running (you can test it by pinging google, yahoo or someone else) it's time to add the tap interface. Most of this is taken from the User's Guide, but we're not making a script right now. The commands are fairly similar though. Say your user name is john.

VBoxTunctl -b -u john

You should see tap0 echoed on the screen.

ifconfig tap0 up
brctl addif br0 tap0

Insert an iptables rule allowing traffic to the bridge. Before starting VirtualBox, I run (in Fedora and CentOS)

iptables -I RH-Firewall-1-INPUT -i br0 -j ACCEPT

If you're not using a RedHat based system, change RH-FIREWALL-1-INPUT to INPUT.

Now, when you run VirtualBox and edit the settings of the guest O/S, in the networking section choose Attached to Host Interface and for Interface Name choose tap0.

Now, when you start your guest system, if you're on DHCP, it can get its address dynamically. Otherwise, give it an IP address in that network, for example, 192.168.1.56 with the same subnet mask of 255.255.255.0 and gateway of 192.168.1.1.

In some cases, I've been able to leave my default iptables settings alone and everything works. If not, I add the bridge to allowed interfaces. When finished, after closing VirtualBox, you can bring things back to the way they were before. Bring down the tap interface and remove it.

ifconfig tap0 down
VBoxTunctl -d tap0

You can also remove the bridge and give everything back to eth0. Keep in mind that this will, once again, temporarily disconnect you from the network.

ifconfig br0 down

You are now off the network. You can now remove the bridge.

brctl delbr br0

Bring eth0 back up, either by running dhclient eth0 or giving it an address with the same commands we used earlier to give br0 an address.

ifconfig eth0 192.168.1.55 netmask 255.255.255.0
route add -net 192.168.1.0 netmask 255.255.255.0 eth0

route add default gw 192.168.1.1 eth0
Post Reply