# virtualbox and network bridging [solved]

## carpman

Hello, trying to get Virtualbox setup with bridging network so i can give guest OS own IP, i have follwed guide on gentoo-wiki but get following error:

```

SIOCADDRT: Network is unreachable
```

nano -w /etc/conf.d/net 

```

## Regular network

#config_eth0=( "192.168.1.5 netmask 255.255.255.0 brd 192.168.1.255" )

#routes_eth0=( "default gw 192.168.1.1" )

#

#

#

## Setup for Vurtualbox bridging

#

#

#the interface is really replaced by br0 for outgoing, so if you had dhcp here, you'll use dhcp in br0

config_eth0=( "null" )

#this specifies that interface vbox0 will be a tap interface and use the tunctl command to generate itself

tuntap_vbox0="tap"

#ALL interfaces part of a bridge should be null, otherwise oddities may occur.

config_vbox0=( "null")

# you can specify an owner of the interface if you want to run virtual box as a non root user

# [COMMENT from a reader: VirtualBox should never be run as root]

#tunctl_vbox0=("-u adm")

#If you'd prefer a dynamic ip address for the machine, use

#config_br0=( "dhcp" )

config_br0=( "192.168.1.8 netmask 255.255.255" )

routes_br0=( "default via 192.168.1.1" )

#this specifies the bridging information

bridge_br0="eth0 vbox0"

#Make sure your baselayout is recent enough to support this

depend_br0()

{

         need net.eth0

         need net.vbox0

}

brctl_br0=( "setfd 0")

```

Not sure if it is correct as am little confused as to what and were i set IP for host and guest?

cheers

----------

## Section_8

I followed that same guide to set up bridging and my /etc/conf.d/net is similar to yours & working fine.  Do you run a firewall?  I had to add an iptables rule to get it to work.

I set up a dhcp reservation in my router (based on the VM's mac address) to give the guest an IP address.

----------

## carpman

 *Section_8 wrote:*   

> I followed that same guide to set up bridging and my /etc/conf.d/net is similar to yours & working fine.  Do you run a firewall?  I had to add an iptables rule to get it to work.
> 
> I set up a dhcp reservation in my router (based on the VM's mac address) to give the guest an IP address.

 

My firewall is a smoothwall box which is also my router and dhcp server so i have no firewall on workstation, i would prefer guest to have static IP as well.

Could you post content of your /etc/conf.d/net

cheers

----------

## Section_8

```
# This blank configuration will automatically use DHCP for any net.*

# scripts in /etc/init.d.  To create a more complete configuration,

# please review /etc/conf.d/net.example and save your configuration

# in /etc/conf.d/net (this file :]!).

# dns_domain_lo="moores.net"

#

#  dhcp configuration:

# config_eth0=( "dhcp" )

# dhcpcd_eth0="-Y -N"

#

#  Configuration for static IP address:

modules=("ifconfig")

# config_eth0=( "192.168.0.194/24 broadcast 192.168.0.255" )

# routes_eth0=( "default via 192.168.0.1" )

# dns_servers_eth0=("192.168.0.1")

# brigding for windows virtual machine:

config_eth0=("null")

# define vbox0 as a tap interface:

tuntap_vbox0="tap"

config_vbox0=("null")

#  set userid john as vbox0 owner:

tunctl_vbox0=( "-u john" )

config_br0=( "192.168.0.194/24 broadcast 192.168.0.255" )

# config_br0=( "dhcp" )

# dhcpcd_br0="-Y -N"

routes_br0=( "default via 192.168.0.1" )

dns_servers_br0=("192.168.0.1")

bridge_br0="eth0 vbox0"

depend_br0()

{

    need net.eth0

    need net.vbox0

}

brctl_br0=( "setfd 0" )

```

----------

## carpman

Hello, ok i tried you setup with couple of changes to get it working on my network.

I can get to start network without errors and give host on br0 a fixed IP but as yet no IP for vbox0

```
## Bridging setup

# dns_domain_lo="moores.net"

#

#  dhcp configuration:

# config_eth0=( "dhcp" )

# dhcpcd_eth0="-Y -N"

#

#  Configuration for static IP address:

modules=("ifconfig")

# config_eth0=( "192.168.0.194/24 broadcast 192.168.0.255" )

# routes_eth0=( "default via 192.168.0.1" )

# dns_servers_eth0=("192.168.0.1")

# brigding for windows virtual machine:

config_eth0=("null")

# define vbox0 as a tap interface:

tuntap_vbox0="tap"

config_vbox0=("null")

#  set userid michael as vbox0 owner:

tunctl_vbox0=( "-u michael" )

config_br0=( "192.168.1.5 broadcast 192.168.1.255" )

# config_br0=( "dhcp" )

# dhcpcd_br0="-Y -N"

routes_br0=( "default via 192.168.1.1" )

dns_servers_br0=("192.168.1.1")

bridge_br0="eth0 vbox0"

depend_br0()

{

    need net.eth0

    need net.vbox0

}

brctl_br0=( "setfd 0" )

```

The problem i do have is that with this setup is that on br0 now get loads of packet loss that i don't get with standard setup?

with br0

```

# ping -c3 www.google.com

PING www.google.com (74.125.77.104) 56(84) bytes of data.

64 bytes from ew-in-f104.google.com (74.125.77.104): icmp_seq=1 ttl=243 time=28.7 ms

64 bytes from ew-in-f104.google.com (74.125.77.104): icmp_seq=2 ttl=243 time=29.4 ms

--- www.google.com ping statistics ---

3 packets transmitted, 2 received, 33% packet loss, time 6032ms

rtt min/avg/max/mdev = 28.736/29.117/29.499/0.417 ms

 # ping -c3 www.google.com

PING www.google.com (74.125.77.103) 56(84) bytes of data.

64 bytes from 74.125.77.103: icmp_seq=1 ttl=243 time=30.7 ms

--- www.google.com ping statistics ---

3 packets transmitted, 1 received, 66% packet loss, time 11032ms

rtt min/avg/max/mdev = 30.710/30.710/30.710/0.000 ms

```

But with standard setup

```

# ping -c3 www.google.com

PING www.l.google.com (74.125.77.147) 56(84) bytes of data.

64 bytes from ew-in-f147.google.com (74.125.77.147): icmp_seq=1 ttl=243 time=35.3 ms

64 bytes from ew-in-f147.google.com (74.125.77.147): icmp_seq=2 ttl=243 time=38.1 ms

64 bytes from ew-in-f147.google.com (74.125.77.147): icmp_seq=3 ttl=243 time=36.0 ms

--- www.l.google.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time 2002ms

rtt min/avg/max/mdev = 35.360/36.520/38.132/1.196 ms

```

So something is not right here?

any ideas?

cheers

----------

## Section_8

I don't see anything wrong, but I'm not an expert either - I just muddled through it until I got it to work.  What do you mean by standard setup - NAT?  If I run a guest with NAT, ping doesn't work at all - no packets get through.

This is what I see from my guest (kubuntu):

```
john@virtlinux:~$ ifconfig

eth1      Link encap:Ethernet  HWaddr 08:00:27:7c:37:9b

          inet addr:192.168.0.196  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::a00:27ff:fe7c:379b/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:41 errors:0 dropped:0 overruns:0 frame:0

          TX packets:63 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:5222 (5.2 KB)  TX bytes:7716 (7.7 KB)

          Interrupt:11 Base address:0xc020

lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:40 errors:0 dropped:0 overruns:0 frame:0

          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0

          RX bytes:2000 (2.0 KB)  TX bytes:2000 (2.0 KB)

john@virtlinux:~$ ping -c4 www.google.com

PING www.l.google.com (74.125.47.147) 56(84) bytes of data.

64 bytes from yw-in-f147.google.com (74.125.47.147): icmp_seq=1 ttl=243 time=61.5 ms

64 bytes from yw-in-f147.google.com (74.125.47.147): icmp_seq=2 ttl=243 time=38.8 ms

64 bytes from yw-in-f147.google.com (74.125.47.147): icmp_seq=3 ttl=243 time=41.5 ms

64 bytes from yw-in-f147.google.com (74.125.47.147): icmp_seq=4 ttl=243 time=40.9 ms

--- www.l.google.com ping statistics ---

4 packets transmitted, 4 received, 0% packet loss, time 3009ms

rtt min/avg/max/mdev = 38.825/45.705/61.561/9.211 ms

john@virtlinux:~$

```

----------

## carpman

Hello, ok i think we have crossed swords here.

The packet loss was with host, VB was not even loaded, which why it is so strange to get packet loss on host when bridging is used as opposed to standard setup when there is none, and by standard setup i mean just having /etc/conf.d/net set to static IP for host with no bridging!

cheers

----------

## Section_8

Sorry for the misunderstanding.  Once I got my firewall set up, I don't remember having much trouble with bridging from the host side, just the guest.

----------

## carpman

Not sure why but no longer having packet loss issues with bridging and all works fine, can even set fixed IP in guest  :Smile: 

Thanks for help.

----------

