Using a linux box as a bridge

A bridge is a way to connect more than one Ethernet segments together in a protocol independent way. Packets are forwarded based on Ethernet address, rather than IP address (like a router does). Since forwarding is done at Layer 2, all protocols can go transparently through a bridge.

Now imagine you want to build a bridge with you own PC equipped with three different interfaces: a wlan two Gb Ethernet 1000 Base-T and a Gb Ethernet 1000 Base-SX (Fiber Optic connection).

Linux gives you the ability to do that.

You only need to install the brctl command (yet installed on most of Linux dIstributions).

 

A simple bridge configuration

Referring to the above picture we configure a bridge bitween the four interfaces, remeber that you need to be root to issue the following commands:

# ifconfig wlan0 0.0.0.0
# ifconfig eth0 0.0.0.0
# ifconfig eth1 0.0.0.0
# ifconfig eth2 0.0.0.0
# brctl addbr bridge0
# brctl addif bridge0 wlan0
# brctl addif bridge0 eth0
# brctl addif bridge0 eth1
# brctl addif bridge0 eth2
# ifconfig bridge0 up

If you issue the ifconfig command you should obtain an output like the following:

 

~# ifconfig

bridge0   Link encap:Ethernet  HWaddr yy:yy:yy:yy:yy:yy

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:0

          RX bytes:11501 (11.2 KiB)  TX bytes:9714 (9.4 KiB)


eth0      Link encap:Ethernet  HWaddr yy:yy:yy:yy:yy:yy

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100

          RX bytes:3023 (2.9 KiB)  TX bytes:3475 (3.3 KiB)


eth1      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100

          RX bytes:3023 (2.9 KiB)  TX bytes:3475 (3.3 KiB)


eth2      Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100

          RX bytes:3023 (2.9 KiB)  TX bytes:3475 (3.3 KiB)


lo        Link encap:Local Loopback

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

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

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

          collisions:0 txqueuelen:0

          RX bytes:636 (636.0 B)  TX bytes:636 (636.0 B)

 

 

This configuration is a configuration for a transparent bridge, it looks like a bridge you can buy in a Store. But your Linux box is a more intelligent system, so you can add services. If you want to add some services like snmp (to check the status of your Linux system) or a NTP service or a telnetd daemon or whatever you want, you can add an IP address to your bridge interface.

Simply issue the following commands:

 

# ifconfig bridge0 192.2.2.5 netmask 255.255.255.0

 

# ifconfig bridge0

 

br0       Link encap:Ethernet  HWaddr yy:yy:yy:yy:yy:yy

          inet addr:192.2.2.5  Bcast:192.2.2.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:0

          RX bytes:19714 (19.2 KiB)  TX bytes:12640 (12.3 KiB)

 
Note that the bridge0 interface will take the MAC Address from the first interface added to the bridge itself.
 
Gg1
Posted by at July 5, 2011
Filed in category: linux, sysadmin, UNIX TLC, and tagged with: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <font color="" face="" size=""> <span style="">

Statistical data collected by Statpress SEOlution (blogcraft).