Network bridge

Introduction

A network bridge can be used to connect two independent network segments at layer 2 level (much like a router). Common applications include transparent proxying, transparent filtering (using iptables) and saving money on hardware as some mainboards come with two PHY interfaces. For this how-to, eth0 and eth1 are used but of course they can be replaced by whatever you need.
The way bridging works on Linux is that a bridging device is created (brX) that contains at least two network devices as ports (e.g. ethX or pppX). As the bridge works on layer 2, no IP addresses are needed on the port devices - on a typical setup, the bridging device itself will receive the IP (e.g. via DHCP).

Kernel

[Collapse]
Kernel configuration

[*] Networking support  --->
   Networking options  --->
      <M> 802.1d Ethernet Bridging
 This is a deprecated template. Help us update this template!

Installation

root #emerge --ask bridge-utils

Host Configuration (using OpenRC init scripts)

First, we need to add the bridge device to the /etc/conf.d/net file. As an example, bridge configuration with DHCP:
Note
Note that it is important to include 'setfd 0' and 'sethello 10' in order to bring the interface up quickly. Other values will cause network packets to be dropped for the first 30 seconds after the bridge has become active. This in turn could prevent DHCP from working.
[Collapse]
File/etc/conf.d/net

# bridge ports defined empty to avoid DHCP being run for their configuration
config_eth0="null"
config_eth1="null"

# bridge
config_br0="dhcp"
brctl_br0="setfd 0
sethello 10
stp off"
bridge_br0="eth0 eth1"
 This is a deprecated template. Help us update this template!
More documentation can be found in /usr/share/doc/netifrc-*/net.example.bz2.
Next, create the init script and start the interface as follows:
root #ln -s /etc/init.d/net.lo /etc/init.d/net.br0
root #/etc/init.d/net.br0 start
Finally, to make sure the bridge is automatically set up on subsequent boots, run:
root #rc-update add net.br0 default

Host Configuration (using systemd)

As of systemd >= 210, a special service called systemd-networkd is available for network configuration, including bridge construction.
The basic procedure of creating a network configuration with systemd-networkd is creating several .network and .netdev files.
First, we need to create a bridge. With systemd-networkd this is as simple as creating a new .netdev file:
[Collapse]
File/etc/systemd/network/MyBridge.netdev

[NetDev]
Name=br0
Kind=bridge
 This is a deprecated template. Help us update this template!
After we created the bridge definition, we can assign the interfaces to this bridge:
[Collapse]
File/etc/systemd/network/MyEth.network

[Match]
Name=eth*

[Network]
Bridge=br0
 This is a deprecated template. Help us update this template! You can match multiple interfaces to be attached to the bridge
Notice that this bridge is still not active, this can be solved by creating a .network definition to actually use the bridge.

DHCP:

[Collapse]
File/etc/systemd/network/MyBridge.network

[Match]
Name=br0

[Network]
DHCP=v4
 This is a deprecated template. Help us update this template!

Static:

[Collapse]
File/etc/systemd/network/MyBridge.network

[Match]
Name=br0

[Network]
DNS=192.168.1.1
Address=192.168.1.2/24
Gateway=192.168.1.1
 This is a deprecated template. Help us update this template! Gateway is only necessary if you intend to use your physical network interface as access to another network. If you're using the bridge as a private network, omit it as systemd-networkd will add the bridge as a default route when the Gateway option is set.
Do remember to enable and start the systemd-networkd service.

Ref:http://wiki.gentoo.org/wiki/Network_bridge

Comments

Popular posts from this blog

WMI Static Port configuration

Optimizing your JVM for Best Performance

How do I disable FOREIGN KEY checking for the time of database schema migration?