Bridges with Linux

From Guifi - Media-pool Common Repository

Revision as of 19:05, 29 March 2014 by Lib2know (Talk)

Bridge Utilities in Linux

The bridge-utils package

Installation:

$ sudo apt-get install bridge-utils

Commands:

$ dpkg -L bridge-utils | grep bin
/usr/sbin
/usr/sbin/brctl

Configuration files:

$ dpkg -L bridge-utils | grep etc
/etc
/etc/network
/etc/network/if-pre-up.d
/etc/network/if-pre-up.d/bridge
/etc/network/if-post-down.d
/etc/network/if-post-down.d/bridge

Resources:

The bridge control command 'brctl'

Show the bridges:

$ brctl show 
 bridge name     bridge id               STP enabled     interfaces
 br0             8000.001601a1a9b7       no              eth0
                                                         wlan0
 br1             8000.000000000000       no              

Create a new bridge:

$ brctl addbr br1

Add/delete interfaces a un bridge:

$ brctl delif
$ brctl addif

Creation of a bridge

We install the package bridge-utils and the file /etc/network/interfaces. Then we create an interface as a bridge from eth0:

$ cat /etc/network/interfaces

auto lo
iface lo inet loopback

auto br0
iface br0 inet static
 address 192.168.1.2
 netmask 255.255.255.0
 gateway 192.168.1.1
 bridge_ports eth0

auto eth0
iface eth0 inet manual

We can use DHCP, as well:

$ cat /etc/network/interfaces

auto lo
iface lo inet loopback

auto br0
iface br0 inet dhcp
 bridge_ports eth0

auto eth0
iface eth0 inet manual
NOTE: Note how the interface eth0 is manually configured and the line bridge_ports eth0.


We restart to initialize the network:

$ sudo /etc/init.d/networking restart

From now on the eth0 interface can be observed by executing ifconfig:

$ ifconfig
br0       Link encap:Ethernet  HWaddr 00:30:1B:B7:CD:B6  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::230:1bff:feb7:cdb6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28932 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28277 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:24356075 (23.2 MB)  TX bytes:17213164 (16.4 MB)

eth0      Link encap:Ethernet  HWaddr 00:30:1B:B7:CD:B6  
          inet6 addr: fe80::230:1bff:feb7:cdb6/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20788 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14681 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:23664360 (22.5 MB)  TX bytes:1995733 (1.9 MB)
          Interrupt:20 


It is a non configured interface (Dummy). This is normal, check the network if it still works.

The package uml-utilities

Installation of User Mode Linux utilities package (uml-utilities):

$ sudo apt-get install uml-utilities

The User Mode Linux package contains tools to create TAP interfaces. Add permissions to access the user interface:

$ sudo gpasswd -a <user> uml-net

For example:

$ sudo gpasswd -a sergi uml-net

We need to restart to apply the permissions.

We edit the file /etc/network/interfaces To add the TAP interface by appending:

auto tap0
iface tap0 inet manual
     up ifconfig $IFACE 0.0.0.0 up
     down ifconfig $IFACE down
     tunctl_user <user>

We replace the placeholer <user> with out username. For example:

auto tap0
iface tap0 inet manual
     up ifconfig $IFACE 0.0.0.0 up
     down ifconfig $IFACE down
     tunctl_user sergi
     bridge_ports eth0 tap0

Restart to initialize the network:

$ sudo /etc/init.d/networking restart

The command tunctl

Now we create a bridge:

$ sudo tunctl -t tap1 -u sergi
$ sudo chmod 666 /dev/net/tun

And:

$ sudo brctl addbr br0 
$ sudo ifconfig eth0 0.0.0.0 promisc 
$ sudo brctl addif br0 eth0
$ dhclient br0


$ sudo brctl addif br0 tap1 

Recursos:

Resources

Personal tools