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).

Installation
Install :

Host Configuration (using OpenRC init scripts)
First, we need to add the bridge device to the file. As an example, bridge configuration with DHCP:

More documentation can be found in.

Next, create the init script and start the interface as follows:

Finally, to make sure the bridge is automatically set up on subsequent boots, run:

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:

After we created the bridge definition, we can assign the interfaces to this bridge:

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.

Static:
Do remember to enable and start the systemd-networkd service.

External Resources

 * Official Linux network bridge documentation
 * Generic Linux network bridge how-to
 * Article on the inofficial gentoo wiki with VLAN and iptables examples