Sunday, October 9, 2011

Linux Brdige

Installing the software


The program you’re going to need is called brctl and is included in bridge-utils. Find it in Synaptic, or install it using this command:
aptitude install bridge-utils
This program will allow us to set up and use the bridge interface. The bridge interface appears as a new interface in ip link, much like eth0 or eth1. It doesn’t physically exist on your computer, but instead it is a virtual interface that just takes the packets from one physical interface, and transparently routes them to the other.


Setting up your Bridge


Manual bridge setup


First step to creating the bridge network is actually creating it. Issue this command to get the ball rolling and create the new interface.
brctl addbr br0
The name br0 is totally up to you, this is just an example name that I’ve chosen for the wiki article. Anyway, now that you have your bridge device, you have to add the interfaces that are gonna be bridged. You can cross-check the enumeration of your ethernet devices with (eth0, eth1, etc. is common):
ip addr show
Add both the interface with the second computer, and the interface that leads to the existing network. Do it with this command:
brctl addif br0 eth0 eth1
This will add the two interfaces eth0 and eth1 to bridge br0. Simple enough. There’s no distinction with how you add the bridges, or what order you do it, or any special commands you have to add to distinguish them. So don’t worry about that.


Well, now we have our bridges, so bring all the interfaces up, and you’ll be set!


Configuring bridging in /etc/network/interfaces


- To make your bridge a little more permanent, you’re gonna need to edit /etc/network/interfaces. Using our example names, make it look like this and you’re set (if you want to use DHCP):



 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).

 # The loopback network interface
 auto lo br0
 iface lo inet loopback


 # Set up interfaces manually, avoiding conflicts with, e.g., network manager
 iface eth0 inet manual
 iface eth1 inet manual


 # Bridge setup
 iface br0 inet dhcp
 bridge_ports eth0 eth1


To bring up your bridge, you just have to issue  # ifup br0 and it’ll bring up the other necessary interfaces without anything in your interfaces file about the bridged interfaces.


- If you like static IP’s, then you can just add the static IP options under the br0 interface setup. Kinda like this:



 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5).

 # The loopback network interface
 auto lo br0
 iface lo inet loopback


 # Set up interfaces manually, avoiding conflicts with, e.g., network manager
 iface eth0 inet manual
 iface eth1 inet manual


 # Bridge setup
 iface br0 inet static
        bridge_ports eth0 eth1
        address 192.168.1.2
        broadcast 192.168.1.255
        netmask 255.255.255.0
        gateway 192.168.1.1


Source Link: http://wiki.debian.org/BridgeNetworkConnections

No comments:

Post a Comment