What it is¶
The Linux bridge is an in-kernel software implementation of a Layer 2 switch — think of it as a virtual switch chassis, with physical NICs and virtual (tap/veth) interfaces as the cables plugged into it. It's the standard way to give VMs and containers real presence on the physical LAN, and the building block underneath most virtualization networking (libvirt, Docker's bridge driver).
Installing bridge-utils¶
sudo yum -y install bridge-utils # RHEL/CentOS (legacy tool; `ip link` covers most of this natively on modern kernels)
Modern systems can create and manage bridges entirely through ip link / iproute2 without bridge-utils — see below.
Creating a bridge with iproute2 (modern approach)¶
sudo ip link add name br0 type bridge
sudo ip link set br0 up
sudo ip link set eth0 master br0 # attach a physical NIC to the bridge
sudo ip addr add 192.168.0.50/24 dev br0
Legacy: RHEL/CentOS sysconfig network-scripts¶
Still relevant on older RHEL-family systems using the legacy network service instead of NetworkManager:
cat /etc/sysconfig/network-scripts/ifcfg-eth0
NAME="eth0"
DEVICE="eth0"
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
NM_CONTROLLED=no
BRIDGE="br0"
cat /etc/sysconfig/network-scripts/ifcfg-br0
NAME="br0"
DEVICE="br0"
ONBOOT=yes
BOOTPROTO=dhcp
TYPE="Bridge"
DNS1="192.168.0.1"
For managing bridges via NetworkManager instead (the modern, distro-agnostic path), see the nmcli guide.
Legacy: brctl¶
brctl (from bridge-utils) is the old bridge management tool. It still works where installed but is deprecated in favour of ip link and bridge.
| brctl | Modern equivalent |
|---|---|
brctl addbr br0 |
ip link add name br0 type bridge |
brctl delbr br0 |
ip link del br0 |
brctl addif br0 eth0 |
ip link set eth0 master br0 |
brctl delif br0 eth0 |
ip link set eth0 nomaster |
brctl show |
bridge link show / ip -d link show type bridge |
brctl showmacs br0 |
bridge fdb show br br0 |
brctl stp br0 on |
ip link set br0 type bridge stp_state 1 |
brctl setageing br0 300 |
ip link set br0 type bridge ageing_time 30000 (centiseconds) |
brctl setbridgeprio br0 prio |
ip link set br0 type bridge priority <n> |
brctl show
bridge name bridge id STP enabled interfaces
br0 8000.d4bed99689c9 yes eth0
virbr0 8000.52540055714f yes virbr0-nic
The bridge with the lowest priority/MAC becomes the STP root. The 4-digit prefix in the ID (8000) is the priority.
Legacy: static-IP ifcfg files (RHEL network-scripts)¶
Alternative to the DHCP ifcfg-br0 above, with a static address:
DEVICE="br0"
BOOTPROTO="static"
IPADDR="192.168.0.50"
NETMASK="255.255.255.0"
GATEWAY="192.168.0.1"
DNS1="192.168.0.1"
ONBOOT="yes"
TYPE="Bridge"
NM_CONTROLLED="no"
Assigning an address to a bare virtual interface by hand: sudo ip addr add 192.168.1.13/24 dev vnet0 && sudo ip link set vnet0 up. The old ifconfig vnet0 192.168.1.13 netmask 255.255.255.0 up does the same.
Inspecting a bridge¶
bridge link show # port membership
bridge fdb show br br0 # forwarding database (learned MAC addresses)
ip -d link show br0 # bridge details (STP state, etc.)
Cheat sheet¶
ip link add name br0 type bridge # create bridge
ip link set eth0 master br0 # attach a NIC
bridge link show # inspect membership
bridge fdb show br br0 # MAC learning table