To Configure a network bridges in Linux is a common method of merging two or more network interfaces into a single virtual interface. Bridging can help improve network performance, ensure redundancy, and support load balancing. A network bridge allows a Linux system to share its internet connection with other devices, making it useful for scenarios like connecting a system without internet access to one with an active connection via Ethernet.
A network bridge operates at the Data Link Layer (Layer 2), forwarding traffic based on MAC addresses. Linux supports both hardware and software bridges, enabling hosts to act as transparent bridges between networks. The Linux kernel has included bridging support since versions 2.4 and 2.6, adhering partially to the ANSI/IEEE 802.1d standard.
This tutorial will walk you through configuring a network bridge on various Linux distributions, such as Debian, Ubuntu, RHEL, and CentOS, using tools like brctl
, iproute2
, nmcli
, and netplan
.
1. Configuring a Network Bridge on Debian/Ubuntu with brctl
1.1 Installing the Network Bridge Utilities
To configure a network bridge on Debian or Ubuntu, you’ll need to install the bridge-utils
package, which contains the brctl
utility. Run the following command:
sudo apt install bridge-utils
This tool allows you to create and manage virtual bridge interfaces.
Note: Ensure that your network cards are correctly installed and in the DOWN state before proceeding. Do not assign IP addresses or enable DHCP on any of the Ethernet interfaces until the bridge is fully configured.
1.2 Creating a Bridge Interface
Create a new bridge interface with:
sudo brctl addbr br0
You can choose any name for the bridge interface, such as br0
. To delete a bridge, use:
sudo brctl delbr br0
1.3 Adding Devices to the Bridge
To add Ethernet interfaces to the bridge:
sudo brctl addif br0 ens18 ens19
This adds interfaces ens18
and ens19
to the br0
bridge.
1.4 Viewing Bridge Status
To view the current bridge status:
sudo brctl show
To see the MAC addresses of traffic being forwarded through the bridge:
sudo brctl showmacs br0
1.5 Configuring Permanent Bridging
To make the bridge configuration permanent, edit /etc/network/interfaces
:
# The loopback network interface<br>auto lo<br>iface lo inet loopback<br><br># Set up interfaces manually<br>iface ens18 inet manual<br>iface ens19 inet manual<br><br># Bridge setup<br>iface br0 inet dhcp<br>bridge_ports ens18 ens19
You can also configure a static IP address for the bridge:
iface br0 inet static
bridge_ports ens18 ens19
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1
Restart the networking service:
sudo systemctl restart networking
2. Configuring a Network Bridge on RHEL/CentOS/AlmaLinux with brctl
2.1 Installing Bridge Utilities
Install the bridge-utils
package on RHEL/CentOS/AlmaLinux:
sudo yum install bridge-utils
2.2 Creating a Bridge Interface
Create a file named ifcfg-br0
in the /etc/sysconfig/network-scripts/
directory with the following configuration:
DEVICE=br0<br>TYPE=Bridge<br>IPADDR=192.168.0.2<br>NETMASK=255.255.255.0<br>ONBOOT=yes<br>NM_CONTROLLED=no<br>DELAY=0
2.3 Adding Interfaces to the Bridge
Configure the Ethernet interface with the following in ifcfg-ethX
:
DEVICE=ethX<br>TYPE=Ethernet<br>ONBOOT=yes<br>NM_CONTROLLED=no<br>BRIDGE=br0
Restart the network service:
sudo service network restart
3. Configuring a Network Bridge on Linux with the ip
Tool
3.1 Installing iproute2
On RHEL/CentOS/AlmaLinux:
sudo yum install iproute
On Debian/Ubuntu:
sudo apt install iproute2
3.2 Creating a Bridge with ip
Create a new bridge:
sudo ip link add name br0 type bridge<br>sudo ip link set br0 up
Delete a bridge:
sudo ip link delete br0 type bridge
3.3 Adding Devices to the Bridge
To add devices to the bridge:
sudo ip link set ens18 master br0<br>sudo ip link set ens19 master br0
3.4 Viewing Bridge Status
View the bridge status:
bridge link
4. Configuring a Network Bridge on Linux with nmcli
4.1 Creating a Bridge with nmcli
To create a new bridge:
sudo nmcli connection add type bridge con-name bridge0 ifname br0
4.2 Adding Devices to the Bridge
Add Ethernet interfaces to the bridge:
sudo nmcli con add type ethernet slave-type bridge con-name bridge0-port0 ifname ens18 master br0<br>sudo nmcli con add type ethernet slave-type bridge con-name bridge0-port1 ifname ens19 master br0
Bring up the bridge:
sudo nmcli con up br0
4.3 Setting a Static IP for the Bridge
Assign a static IP to the bridge:
sudo nmcli connection modify br0 ipv4.addresses 192.168.0.2/24
sudo nmcli connection modify br0 ipv4.gateway 192.168.0.1
4.4 Viewing Bridge Status
To check the bridge status:
nmcli device show
If you follow this guide step by step, you can configure a network bridge on various Linux distributions, using tools like brctl
, ip
, nmcli
, and others. Bridging can be a powerful way to manage your network and increase flexibility across interfaces.