Tuesday, August 3, 2010

Linux Switch (aka Bridge)

In this post Im going to show you how to configure a bridge (switch) in Linux. Here I will present several variations tha I have tested. The base cenário is the following:



# Set the eth1 IP address on the Rigth Laptop

ifconfig eth1 10.0.0.1 netmask 255.0.0.0

# Set the eth1 IP address on the Left Laptop

ifconfig eth1 10.0.0.2 netmask 255.0.0.0


Cenário 1 – No IPs on the Server NICs and Bridge

Server Configuration

# Load the bridge kernel module
modprobe bridge

# Activate eth1 and eth2 interface
ifconfig eth1 up

ifconfig eth2 up

# Create the bridge (virtual interface)
brctl addbr br0

# Add members to th
e bridge

brctl addif br0 eth1
brctl addif br0 eth2


Cenário 2 – No IPs on the Server NICs


Server Configuration

# Load the bridge kernel module
modprobe bridge

# Activate eth1 and eth2 interface
ifconfig eth1 up

ifconfig eth2 up

# Create the bridge (virtual interface)
brctl addbr br0

# Add members to the bridge
brctl addif br0 eth1
brctl addif br0 eth2

# Set the bridge IP address:
ifconfig br0 10.0.0.3 netmask 255.0.0.0

Now both computers are on the same LAN and can ping each other and the bridge interface, but can’t ping with the server NICs. This is like a switch with management ip.


Cenário 3 – IPs on the Server NICs and Bridge


Server Configuration

# Load the bridge kernel module
modprobe bridge

# Activate eth1 and eth2 interface
ifconfig eth1 up

ifconfig eth2 up

# Create the bridge (virtual interface)
brctl addbr br0

# Add members to the bridge
brctl addif br0 eth1
brctl addif br0 eth2

# Set the bridge IP address:
ifconfig br0 10.0.0.3 netmask 255.0.0.0

# Set the bridge IP address:
ifconfig br0 10.0.0.3 netmask 255.0.0.0

# Set the eth1 and eth2 IP address:
ifconfig eth1 10.0.0.4 netmask 255.0.0.0

ifconfig eth2 10.0.0.5 netmask 255.0.0.0

Now both computers are on the same LAN and can ping each other, the bridge interface, and also ping with the server NICs. It's like no switch I have ever seen.

Based On: http://openmaniak.com/openvpn_bridging.php






No comments: