Bridging ...

Questions about Wi-Fi and other network devices, file sharing, firewalls, connection sharing etc
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
miket

Bridging ...

Post by miket »

Hi All,

I've created a bridge with two virtual interfaces attached so that I can have two Virtualbox VMs
use my network connection without using the NAT feature. I have set the network interface to HOST and
entered the vbox1/2 interfaces created below.

The commands used to create the bridge are :

Code: Select all

sudo tunctl -t vbox1 -u miket
sudo tunctl -t vbox2 -u miket
sudo brctl addbr br0
sudo ifconfig wlan0 0.0.0.0 promisc
sudo brctl addif br0 wlan0
sudo dhclient br0
sudo brctl addif br0 vbox1
sudo brctl addif br0 vbox2
sudo ifconfig br0 up
sudo ifconfig vbox1 up
sudo ifconfig vbox2 up
sudo chmod 0666 /dev/net/tun
This works fine, the bridge is created and I can ping the host & VMs from each other ...

The VMs are in the same network as the host, 192.168.1.x ...

The problem I have is that the VMs cannot get a route out to the outside world .... infact they are unable to get out of the bridge ?
The host gets out to the outside world perfectly, I can use the internet on the host without a problem, but neither of the VMs can ?

I thought since the two VMs are in the same network as the host then no NAT or Masquerading is necessary as they are just a few
IP addresses up from the host .... or have I missed something here ??

I've found a few different examples of how to achieve this on the VirtualBox forums however none of them have worked ???

EDIT:
Forgot to mention, the interfaces file for the VM is as follows :

Code: Select all

auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
	address 192.168.1.10
	netmask 255.255.255.0
	network 192.168.1.0
	broadcast 192.168.1.255
	gateway 192.168.1.1
	# dns-* options are implemented by the resolvconf package, if installed
	dns-nameservers 192.168.1.1
	dns-search avanceit.co.uk
EDIT2:
I forgot to add the brctl show O/P :

Code: Select all

# brctl show br0
bridge name     bridge id                              STP enabled     interfaces
br0                 8000.001060947bda                  no                 wlan0, vbox1, vbox2
                                                                                            
Any pointers please as I have gone blind for looking :)

Thanks !

Mike.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
miket

Re: Bridging ...

Post by miket »

Ok, I've done some further investigating into this one ...

I've altered the commands a little, code now looks like this :

Code: Select all

sudo tunctl -t vbox1 -u miket
sudo tunctl -t vbox2 -u miket
sudo chmod 0666 /dev/net/tun
sudo brctl addbr br0
sudo ifconfig eth0 0.0.0.0 promisc
sudo brctl addif br0 eth0
sudo dhclient br0
sudo brctl addif br0 vbox1
sudo brctl addif br0 vbox2
echo "Starting ifconfig of vbox 1 & 2 now ..."
sudo ifconfig vbox1 192.168.1.10 up
sudo ifconfig vbox2 192.168.1.11 up
echo "Complete"
sudo ifconfig br0 up
#  sudo ifconfig vbox1 up
#  sudo ifconfig vbox2 up

echo "Adding routes ..."
sudo route add -host 192.168.1.10 dev vbox1
sudo route add -host 192.168.1.11 dev vbox2
echo "Routes added ..."
echo "Arping ...."
arp -Ds 192.168.1.3 br0 pub
Note I am now using eth0 instead of wlan0 ...
So all I have done is changed the interface from a wireless interface to a 100mb ethernet interface
and the bridging is working a treat !

Using the same code but on the wireless interface (wlan0) results in the bridge not working ....

So it looks like something is broken in the wireless area ???

Has anyone any ideas ?
Is this a known problem and if so will there be a fix ?

Thanks !

Mike.
miket

Re: Bridging ...

Post by miket »

Hi All,

Seems I could be out on a limb with this as no one else has commented, anyways for completeness
here is the final version of the Bridge creation script.

It's all soft coded and can be altered to meet your needs by just editing the variable values.

Code: Select all


#!/bin/bash
#
##################################################################
# Simple Shell script to create virtual interfaces
# for VirtualBox VM's.
#
# This script is released into the public domain as is without
# any guarantees !
####################################################################

PATH=/sbin:/usr/sbin:/bin:/usr/bin

# Set number of Virtual Interfaces (VI's) Req'd
NUMVI=4

# Set the owner of the interfaces
# (YOUR LOGIN NAME)
OWNER=miket

# Set which External facing interface to use
EXTIF=eth0

# Set the name of the Virtual interfaces
INTIF=vbox

# Set IP range to use for Virtual Interfaces 
# (Excluding HOST part of IP Address)
NETIP=192.168.1.

# Set 1st HOST part of IP Address range
HOSTIP=10

# Set the name of the bridge
BRIDGE=br0

# Create the basic bridge ready to add the VI's to ...
sudo brctl addbr $BRIDGE

# Set the External facing interface to promiscuous mode 
# and add it to the bridge. Once added grab an IP address 
# from the DHCP server.
#
# NOTE: IP Address is tied to MAC address on DHCP server thus
#       interface will always get the same IP Address.
#       (This is equivalent of using STATIC IP Addressing!)
sudo ifconfig $EXTIF 0.0.0.0 promisc
sudo brctl addif $BRIDGE $EXTIF
sudo dhclient $BRIDGE

# Set COUNTER to zero ready to start work!
COUNT=0

# Now lets start building our bridge

while [ $COUNT -lt $NUMVI ]
	do
		sudo tunctl -t $INTIF$COUNT
		sudo brctl addif $BRIDGE $INTIF$COUNT
		sudo ifconfig $INTIF$COUNT $NETIP$HOSTIP up
		sudo route add -host $NETIP$HOSTIP dev $INTIF$COUNT
		let COUNT=$COUNT+1
		let HOSTIP=$HOSTIP+1
	done

# set read/write priv's
sudo chmod 0666 /dev/net/tun

# Make sure the bridge is up
ifconfig $BRIDGE up

# Arp ...
BRIDGEIP=`sudo ifconfig $BRIDGE | grep addr: | awk -F: '{print $2}'| awk '{print $1}'`
sudo arp -Ds $BRIDGEIP $BRIDGE pub


You will need to save it and chmod 700 to be able to execute it.

Enjoy !

Mike.
Locked

Return to “Networking”