Network bridge (简体中文)
A bridge is a piece of software used to unite two or more network segments. A bridge behaves like a virtual network switch, working transparently (the other machines don't need to know or care about its existence). Any real devices (e.g.
eth0) and virtual devices (e.g.
tap0) can be connected to it.
This article explains how to create a bridge that contains at least an ethernet device. This is useful for things like the bridge mode of QEMU, setting a software based access point, etc.
Creating a bridge
There are a number of ways to create a bridge.
This section describes the management of a network bridge using the brctl tool from the official repositories. See
man brctl for full listing of options.
Create a new bridge:
# brctl addbr bridge_name
Add a device to a bridge, for example
# brctl addif bridge_name eth0
Show current bridges and what interfaces they are connected to:
$ brctl show
Set the bridge device up:
# ip link set up dev bridge_name
Delete a bridge, you need to first set it to down:
# ip link set dev bridge_name down # brctl delbr bridge_name
This sections describes the management of a network bridge using the ip tool from thepackage, which is included in the group.
Create a new bridge and change its state to up:
# ip link add name bridge_name type bridge # ip link set dev bridge_name up
To add an interface (e.g. eth0) into the bridge, it must be first set to promiscuous mode and its state must be up:
# ip link set dev eth0 promisc on # ip link set dev eth0 up
Adding the interface into the bridge is done by setting its master to
# ip link set dev eth0 master bridge_name
To show the existing bridges and associated interfaces, use the bridge utility (also part of
man bridge for details.
# bridge link show
When the bridge is to be deleted, all interfaces should be removed first. Also turn off promiscuous mode and set it down to restore the original state.
# ip link set eth0 promisc off # ip link set eth0 down # ip link set dev eth0 nomaster
When the bridge is empty, it can be deleted:
# ip link delete bridge_name type bridge
See Bridge with netctl.
Gnome's NetworkManager can create bridges, but currently will not auto-connect to them. Open Network Settings, add a new interface of type Bridge, add a new bridged connection, and select the MAC address of the device to attach to the bridge.
Now, find the UUID of the attached device (by default named "bridge0 slave 1"):
$ nmcli connection
Finally, enable that connection:
$ nmcli con up <UUID>
If NetworkManager's default interface for the device you added to the bridge connects automatically, you may want to disable that by clicking the gear next to it in Network Settings, and unchecking "Connect automatically" under "Identity."
Assigning an IP address
When the bridge is fully set up, it can be assigned an IP address:
# ip addr add dev bridge_name 192.168.66.66/24
Tips and tricks
Wireless interface on a bridge
To add a wireless interface to a bridge, you first have to assign the wireless interface to an access point or start an access point with hostapd. Otherwise the wireless interface won't be added to the bridge.
See also Bridging with a wireless NIC on Debian wiki.