SkillPilotAI

bridge / brctl

The bridge command (iproute2) manages a Linux software switch: its ports, MAC table (FDB), VLAN filtering, multicast groups (MDB) and VXLAN VNIs. The bridge itself is created with ip link; brctl from the old bridge-utils package is obsolete.

57.1 What it does, where it runs

ToolWhat it doesStatus
ip linkCreates the bridge and adds portsModern
bridgePorts, FDB, MDB, VLAN, VNI, port flags, monitorModern (iproute2), Linux only
brctlBridges, ports, basic STPLegacy bridge-utils, obsolete

57.2 How the bridge learns MACs

  • br0 is a software switch: PC A on eth1, PC B on eth2, PC C on eth3; the FDB starts empty.
  • On every frame the bridge records source MAC -> ingress port in the FDB.
  • Broadcast or unknown destination MAC: flood out of every port except the one it came in on.
  • Known destination MAC: forward only on that one port.
  • A MAC that stays silent for 300 seconds ages out.
FDB learning: ARP from PC A to PC B
  1. 1.FDB empty; PC A sends an ARP broadcast for PC B

  2. 2.br0 learns 02:..:00:aa on eth1

  3. 3.Broadcast is flooded to eth2 and eth3 (PC C sees only this ARP)

  4. 4.PC B replies; br0 learns 02:..:00:bb on eth2

  5. 5.Destination aa is known: reply forwarded only on eth1

  6. 6.All further pings go only between eth1 and eth2

Silent MACs age out after 300 s

57.3 bridge link show: create the bridge, add ports

Terminal
ip link add br0 type bridgeip link set eth1 master br0ip link set eth2 master br0ip link set eth3 master br0ip link set br0 upbridge link showbridge link show dev eth1ip link show master br0
Output
$ bridge link show10: eth1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 211: eth2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 212: eth3@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 2$ bridge link show dev eth110: eth1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state forwarding priority 32 cost 2$ ip link show master br010: eth1@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br0 state UP mode DEFAULT group default qlen 100011: eth2@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br0 state UP mode DEFAULT group default qlen 100012: eth3@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br0 state UP mode DEFAULT group default qlen 1000
  • Creating a bridge and adding ports is the job of ip link.
  • bridge link show prints the state, priority and cost of every port; dev eth1 shows one port.

57.4 bridge fdb show / get

Terminal
bridge fdb show br br0 dynamicip netns exec pca ping -c 2 192.168.77.12bridge fdb show br br0 dynamicbridge -s fdb show br br0 dynamicbridge fdb get 02:00:00:00:00:bb br br0bridge fdb get 02:00:00:00:00:cc br br0
Output
$ bridge fdb show br br0 dynamic $ ip netns exec pca ping -c 2 192.168.77.1264 bytes from 192.168.77.12: icmp_seq=1 ttl=64 time=0.138 ms64 bytes from 192.168.77.12: icmp_seq=2 ttl=64 time=0.085 ms2 packets transmitted, 2 received, 0% packet loss, time 1004mspcc$ tcpdump -nn -e -i eth019:12:27.645802 02:00:00:00:00:aa > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.168.77.12 tell 192.168.77.11, length 281 packet captured$ bridge fdb show br br0 dynamic02:00:00:00:00:aa dev eth1 master br002:00:00:00:00:bb dev eth2 master br0$ bridge -s fdb show br br0 dynamic02:00:00:00:00:aa dev eth1 used 10/10 master br002:00:00:00:00:bb dev eth2 used 10/10 master br0$ bridge fdb get 02:00:00:00:00:bb br br002:00:00:00:00:bb dev eth2 master br0$ bridge fdb get 02:00:00:00:00:cc br br0Error: Fdb entry not found.
  • The dynamic filter shows only learned MACs: empty at first.
  • After the ping, PC A's MAC is on eth1 and PC B's on eth2; -s adds the used timer.
  • PC C only captured the one ARP broadcast.
  • fdb get looks up one MAC; PC C's is not learned yet: Fdb entry not found.

57.5 bridge monitor + fdb add / replace / del / flush

Terminal
bridge -t monitor fdb      # terminal 2bridge fdb add 02:00:00:00:00:dd \  dev eth3 master staticbridge fdb replace 02:00:00:00:00:dd \  dev eth2 master staticbridge fdb del 02:00:00:00:00:dd \  dev eth2 masterbridge fdb flush dev br0 dynamic
Output
Timestamp: Sun Nov  8 19:12:49 2026 942207 usec02:00:00:00:00:dd dev eth3 master br0 staticTimestamp: Sun Nov  8 19:12:49 2026 942326 usec02:00:00:00:00:dd dev eth3 vlan 1 master br0 staticTimestamp: Sun Nov  8 19:12:51 2026 200932 usec02:00:00:00:00:dd dev eth2 master br0 staticTimestamp: Sun Nov  8 19:12:51 2026 201013 usec02:00:00:00:00:dd dev eth2 vlan 1 master br0 staticTimestamp: Sun Nov  8 19:12:53 2026 834231 usecDeleted 02:00:00:00:00:dd dev eth2 master br0 staticTimestamp: Sun Nov  8 19:12:53 2026 834290 usecDeleted 02:00:00:00:00:dd dev eth2 vlan 1 master br0 staticTimestamp: Sun Nov  8 19:12:55 2026 119164 usecDeleted 02:00:00:00:00:bb dev eth2 master br0Timestamp: Sun Nov  8 19:12:55 2026 119225 usecDeleted 02:00:00:00:00:aa dev eth1 master br0
  • bridge -t monitor fdb shows every FDB change live with a timestamp.
  • add creates a static entry on eth3, replace moves it to eth2, del removes it (monitor prints Deleted).
  • flush dev br0 dynamic clears only the learned MACs of PC A and PC B.
  • monitor also takes link, mdb, vlan and neigh instead of fdb.
Output
local | permanent  local entry, never agesstatic             static, never agesdynamic            ageable entryself | master      driver or bridge FDBuse   sticky       in use, never movesextern_learn       learned by HW/controllerrouter             dst is a router (VXLAN)dst  port  vni     remote VTEP, UDP, VNIsrc_vni  via  nhid VXLAN external, ECMP-- show / get / flush --show brport eth1   one port onlyshow state permanent | vlan 10get MAC dev eth1 vlan 10 | vni 100 selfflush brport eth1 | vlan 10 | permanent[no]static [no]sticky [no]offloaded ...
  • static and permanent entries never age; a sticky entry never moves to another port.
  • dst, port and vni point to a remote VXLAN VTEP; no in front of a flush filter inverts it.

57.6 bridge link set: port settings

Terminal
bridge link set dev eth1 isolated onbridge link set dev eth3 isolated onbridge link set dev eth2 learning off \  flood offip netns exec pca ping -c 2 -W 1 \  192.168.77.13ip netns exec pca ping -c 1 -W 1 \  192.168.77.12bridge link set dev eth1 cost 100 \  priority 16bridge link set dev eth1 state 1bridge link show dev eth1
Output
$ ip netns exec pca ping -c 2 -W 1 192.168.77.13PING 192.168.77.13 (192.168.77.13) 56(84) bytes of data.2 packets transmitted, 0 received, 100% packet loss, time 1021ms$ ip netns exec pca ping -c 1 -W 1 192.168.77.12PING 192.168.77.12 (192.168.77.12) 56(84) bytes of data.1 packets transmitted, 0 received, 100% packet loss, time 0ms$ bridge link set dev eth1 cost 100 priority 16$ bridge link set dev eth1 state 1$ bridge link show dev eth110: eth1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 master br0 state listening priority 16 cost 100
  • Two isolated ports cannot talk to each other: PC A to PC C gets 100% loss.
  • learning off + flood off on eth2: PC B's MAC is not learned and unknown unicast never goes to eth2, so that ping fails too.
  • cost and priority are STP values; state 1 puts the port into listening.
Output
cost 100  priority 32   STP cost, priostate 0..4   disabled listening learning             forwarding blockingguard on       BPDU arrives: port disabledroot_block on  never becomes root porthairpin on     back out same port (VEPA)learning  flood  bcast_flood  mcast_floodfastleave on   stop at once on IGMP leavemcast_router 0|1|2   router port modemcast_to_unicast on  per-host copyneigh_suppress  vlan_tunnel   VXLANisolated   locked (only hosts in FDB)backup_port eth2  |  nobackup_portlearning_sync  hwmode vepa|veb (self)self = driver, master = bridge (default)
  • guard and root_block protect an edge port from rogue BPDUs; hairpin sends a frame back out of the same port.
  • locked allows only hosts in the FDB; backup_port redirects traffic when carrier is lost.

57.7 bridge vlan: VLAN filtering

VLAN filtering on br0
  1. 1.vlan_filtering 1 on br0; eth1 = VLAN 10, eth2 = VLAN 20 (access ports)

  2. 2.PC A's frame enters on eth1 in VLAN 10

  3. 3.eth2 is not a member of VLAN 10, so the bridge drops it: 100% loss

  4. 4.Add eth2 to VLAN 10 (pvid untagged)

  5. 5.Ping reply comes back

Terminal
ip link set br0 type bridge \  vlan_filtering 1bridge vlan add dev eth1 vid 10 pvid untaggedbridge vlan add dev eth2 vid 20 pvid untaggedbridge vlan add dev eth3 vid 10-30bridge vlan del dev eth1 vid 1bridge vlan del dev eth2 vid 1bridge -com vlan showip netns exec pca ping -c 1 -W 1 \  192.168.77.12bridge vlan add dev eth2 vid 10 pvid untaggedbridge vlan show dev eth2ip netns exec pca ping -c 1 -W 1 \  192.168.77.12
Output
$ bridge -com vlan showport              vlan-ideth1              10 PVID Egress Untaggedeth2              20 PVID Egress Untaggedeth3              1 PVID Egress Untagged                  10-30br0               1 PVID Egress Untagged$ ip netns exec pca ping -c 1 -W 1 192.168.77.12PING 192.168.77.12 (192.168.77.12) 56(84) bytes of data.1 packets transmitted, 0 received, 100% packet loss, time 0ms$ bridge vlan show dev eth2port              vlan-ideth2              10 PVID Egress Untagged                  20 Egress Untagged$ ip netns exec pca ping -c 1 -W 1 192.168.77.1264 bytes from 192.168.77.12: icmp_seq=1 ttl=64 time=0.128 ms1 packets transmitted, 1 received, 0% packet loss, time 0ms
  • pvid untagged: an untagged frame joins this VLAN and leaves without a tag (access port).
  • eth3 is a tagged trunk for VLANs 10-30; the default VLAN 1 is deleted from the access ports.
  • -com prints a VLAN range on one line.
Output
vid 10 pvid untagged  access portvid 10-30              trunk (tagged)del dev eth1 vid 10    delete a VLANvid 10 self            on the bridge devicevid 10 master          software bridgetunnel_info id 1010    VLAN to tunnel idset dev eth3 vid 20 state 0..4 | blockingset ... mcast_router 0|1|2|3show dev eth1          one port only-d vlan show           state, mcast_router-s vlan show           RX / TX per VLANtunnelshow             VLAN-tunnel list
  • self configures the VLAN on the bridge device, master on the software bridge.
  • vlan set gives each VLAN its own STP state (lab: VLAN 20 on eth3 set to blocking, checked with -d); -s gives per-VLAN stats.

57.8 Multicast: vlan global + mdb

Terminal
ip link set br0 type bridge \  mcast_vlan_snooping 1bridge vlan global set dev br0 vid 10 \  mcast_igmp_version 3 mcast_querier 1bridge -j -p vlan global show \  dev br0 vid 10bridge mdb add dev br0 port eth1 \  grp 239.1.1.1 permanent vid 10bridge mdb add dev br0 port eth3 \  grp 239.1.1.1 temp vid 10bridge -s mdb show dev br0
Output
$ bridge -j -p vlan global show dev br0 vid 10                "vlan": 10,                "mcast_snooping": 1,                "mcast_querier": 1,                "mcast_igmp_version": 3,                "mcast_mld_version": 1,                "mcast_last_member_count": 2,                "mcast_startup_query_interval": 3124,                "mcast_membership_interval": 26000,                "mcast_query_interval": 12500,                "mcast_query_response_interval": 1000$ bridge -s mdb show dev br0dev br0 port eth1 grp 239.1.1.1 permanent vid 10    0.00dev br0 port eth3 grp 239.1.1.1 temp vid 10  252.95
  • IGMP snooping sends a group's traffic only to its members' ports.
  • mcast_vlan_snooping 1 turns on per-VLAN snooping; vlan global set enables IGMPv3 and the querier for VLAN 10.
  • mdb add: eth1 is a permanent and eth3 a temp member of 239.1.1.1; only the temp entry has a running timer.
Output
mdb del dev br0 port eth3 grp 239.1.1.1grp 232.1.1.1 src 192.168.77.50  (S,G)grp 01:00:5e:01:01:01 permanent  L2 groupvid 10           VLAN of the membersmdb show dev br0     one bridge only-d mdb show      router ports, proto-- vlan global set dev br0 vid 10 --mcast_snooping 1    snooping on / offmcast_querier 1     IGMP/MLD queriermcast_igmp_version 3  mcast_mld_version 2mcast_last_member_count | _intervalmcast_startup_query_count | _intervalmcast_membership_interval  group timeoutmcast_querier | query _intervalmcast_query_response_interval  max wait
  • If no IGMP report arrives within the membership interval, the group is removed.

57.9 bridge vni: VXLAN VNI filter

Terminal
ip link add vx0 type vxlan dstport 4789 \  local 192.168.77.1 dev br0 \  external vnifilterbridge vni add dev vx0 vni 100 \  remote 192.168.77.50bridge vni add dev vx0 vni 200 \  group 239.1.1.100bridge vni showbridge fdb append 00:00:00:00:00:00 \  dev vxlan100 dst 192.168.77.50bridge fdb append 00:00:00:00:00:00 \  dev vxlan100 dst 192.168.77.51bridge fdb show dev vxlan100
Output
$ bridge vni showdev               vni                group/remotevx0               100                192.168.77.50                  200                239.1.1.100$ bridge fdb show dev vxlan10000:00:00:00:00:00 dst 192.168.77.50 self permanent00:00:00:00:00:00 dst 192.168.77.51 self permanent
  • In VXLAN every layer 2 network has a VNI number.
  • A vx0 in vnifilter mode carries many VNIs: VNI 100 -> remote VTEP 192.168.77.50, VNI 200 -> multicast group 239.1.1.100 (joined for unknown MACs).
  • On an old single-VNI device, fdb append with the all-zero MAC builds a flood list to both VTEPs.

57.10 Global options

Terminal
bridge -Vbridge -d -j -p link show dev eth2 \  | grep -E 'isolated|learning|"flood'bridge -j vlan show dev eth1bridge -batch /tmp/cmds.txtbridge -force -batch /tmp/bad.txtbridge -n pca link showbridge fdb help
Output
$ bridge -Vbridge utility, 6.9.0$ bridge -d -j -p link show dev eth2 \  | grep -E 'isolated|learning|"flood'        "learning": false,        "flood": false,        "isolated": false,$ bridge -j vlan show dev eth1[{"ifname":"eth1","vlans":[{"vlan":10,"flags":["PVID","Egress Untagged"]}]}]$ bridge -batch /tmp/cmds.txt02:00:00:00:00:aa dev eth1 vlan 10 master br002:00:00:00:00:bb dev eth2 vlan 10 master br002:00:00:00:00:cc dev eth3 master br0port              vlan-ideth1              10 PVID Egress Untagged$ bridge -force -batch /tmp/bad.txtCannot find device "nosuch"Command failed /tmp/bad.txt:1eth1              10 PVID Egress Untagged$ bridge -n pca link show$ bridge fdb helpUsage: bridge fdb { add | append | del | replace } ADDR dev DEV              [ self ] [ master ] [ use ] [ router ] [ extern_learn ]              [ sticky ] [ local | static | dynamic ] [ vlan VID ]
  • -V version (6.9.0 here); -d details; -j -p pretty JSON (eth2 shows learning and flood false).
  • -batch runs commands from a file and stops at the first failure; -force keeps going after an error.
  • -n runs inside a namespace; help prints the syntax; -c colour, -o oneline.

57.11 brctl (legacy) and its modern replacements

Terminal
brctl showbrctl showmacs br0 | grep -v yesbrctl addbr br9brctl stp br9 onbrctl setageing br9 120brctl setbridgeprio br9 4096brctl showstp br9 | head -9brctl addif br9 eth3ip link set br9 downbrctl delbr br9
Output
$ brctl showbridge name  bridge id    STP enabled  interfacesbr0    8000.020000000100  no    eth1              eth2              eth3$ brctl showmacs br0 | grep -v yesport no  mac addr    is local?  ageing timer  1  02:00:00:00:00:aa  no      88.34  2  02:00:00:00:00:bb  no      67.41  3  02:00:00:00:00:cc  no      81.24$ brctl showstp br9 | head -9br9 bridge id    1000.000000000000 max age      20.00      bridge max age      20.00 hello time       2.00      bridge hello time     2.00 forward delay      15.00      bridge forward delay    15.00 ageing time     120.00$ brctl addif br9 eth3device eth3 is already a member of a bridge; can't add it to bridge br9.
  • brctl show lists bridges and ports; showmacs shows learned MACs with an ageing timer.
  • addif fails because eth3 is already in br0.
Output
addbr br0       ip link add br0 type bridgedelbr br0       ip link del br0addif br0 eth1  ip link set eth1 master br0delif br0 eth1  ip link set eth1 nomastershow [br0]      bridge link showshowmacs br0    bridge fdb show br br0stp br0 on|off  ... type bridge stp_state 1setageing br0 300  ... ageing_time 30000setgcint br0 4     FDB GC intervalsetbridgeprio br0 4096  ... priority 4096setfd br0 15    ... forward_delay 1500sethello br0 2  ... hello_time 200setmaxage br0 20  ... max_age 2000setpathcost br0 eth1 100  link set costsetportprio br0 eth1 32   link set priority

57.12 Common mistakes

  • Myth: a Linux bridge is a hub that copies every frame to every port. It is a real L2 switch with MAC learning, VLAN filtering, STP and IGMP snooping; in the lab PC C got only the ARP broadcast.
  • Docker's docker0 and KVM's virbr0 are Linux bridges too.
  • Forgetting to delete the default VLAN 1 from access ports when VLAN filtering is on.
  • Trying to add a port that is already in another bridge (can't add it to bridge br9).

57.13 Interview tips

  • brctl vs bridge: brctl (bridge-utils) only handles bridges, ports and basic STP and is obsolete; modern Linux uses ip link to create the bridge and bridge for FDB, VLAN, MDB, VNI and port flags.
  • Unknown unicast (e.g. PC C not in FDB yet) is flooded out of every port except the ingress port; after PC C replies, its MAC is learned on eth3.
  • pvid untagged = access port; vid range (tagged) = trunk.
  • bridge monitor shows FDB/link/VLAN changes live.