Skip to content

Linux bridge management with brctl

brctl is a command-line tool used for managing Linux network bridges, facilitating the connection of multiple network segments to function as a single network^[600-developer__docker__docker-bridge.md]. To utilize this utility, the necessary package must be installed on the system^[600-developer__docker__docker-bridge.md].

Common Commands

The tool provides several commands for creating, modifying, and inspecting bridge interfaces^[600-developer__docker__docker-bridge.md]:

  • Create a bridge: brctl addbr (e.g., brctl addbr br0)^[600-developer__docker__docker-bridge.md]
  • Add an interface: brctl addif (e.g., brctl addif br0 eth0)^[600-developer__docker__docker-bridge.md]
  • Remove an interface: brctl delif (e.g., brctl delif br0 eth0)^[600-developer__docker__docker-bridge.md]
  • Delete a bridge: brctl delbr (e.g., brctl delbr br0)^[600-developer__docker__docker-bridge.md]
  • Show configuration: brctl show^[600-developer__docker__docker-bridge.md]

Configuration and Docker

In a typical configuration, a network bridge aggregates physical interfaces and assigns them a shared IP address^[600-developer__docker__docker-bridge.md]. For example, to set up a bridge named br0, one would create the bridge, assign an IP and netmask (e.g., ifconfig br1 192.168.2.1 netmask 255.255.255.0), and then attach the physical Ethernet interface using brctl addif^[600-developer__docker__docker-bridge.md].

Within Docker environments, brctl is frequently used to replace the default docker0 bridge with a custom bridge (e.g., br1)^[600-developer__docker__docker-bridge.md]. This configuration allows administrators to control the IP subnet used by containers by specifying parameters like DOCKER_OPTS="-b=br1 --fixed-cidr=..." in the Docker configuration file^[600-developer__docker__docker-bridge.md].

Sources

  • 600-developer__docker__docker-bridge.md