use network manger nmcli command to manage linux bridge.

A Linux bridge is a software component in the Linux kernel that connects two or more network interfaces together to form a single network segment. The bridge operates at the data link layer (Layer 2) of the networking stack and can forward Ethernet frames between the connected interfaces.

A Linux bridge can be used to connect multiple physical network interfaces, virtual network interfaces, or a combination of both. It can also be used to create virtual networks by connecting virtual machines or containers to the same bridge. The bridge can be thought of as a virtual switch that allows connected devices to communicate with each other as if they were connected to the same physical switch.

The Linux bridge supports multiple spanning tree protocols, which can prevent loops in the network and ensure redundant paths are available for failover. The bridge can also be configured to filter traffic based on source and destination MAC addresses, VLAN tags, and other criteria.

The Linux bridge can be managed using command-line tools such as ip, brctl, and nmcli. It can also be managed using graphical user interface tools such as NetworkManager or system-config-network.

Create bridge

nmcli connection add type bridge con-name <bridge_name> ifname <bridge_interface_name> Replace <bridge_name> with the desired name for the bridge and <bridge_interface_name> with the desired interface name for the bridge.

sudo nmcli con add ifname br0 type bridge con-name br0

(option)remove an interface from a bridge

nmcli connection modify <interface_name> connection.slave-type "" Replace <interface_name> with the name of the interface to be removed from the bridge.

(option)delete a bridge

nmcli connection delete <bridge_name> Replace <bridge_name> with the name of the bridge to be deleted.

(option)disable STP

STP stands for “Spanning Tree Protocol,” which is a network protocol used to prevent loops in a network topology. It ensures that there is only one active path between any two network devices at a time, preventing broadcast storms and other network problems that can occur when multiple paths are active.

sudo nmcli con modify br0 bridge.stp no

(option)set default route

The ipv4.never-default property in nmcli is used to specify whether a particular IPv4 address should be treated as the default route or not.

When this property is set to yes, the IPv4 address associated with the network interface is not used as the default route for outgoing traffic. Instead, the default route is determined by other means, such as DHCP or manually configured static routes.

Setting ipv4.never-default to yes can be useful in certain scenarios, such as when you want to have multiple network interfaces with their own default routes, or when you have a non-default routing setup that requires a specific default route to be set manually.

On the other hand, if ipv4.never-default is set to no (which is the default value), the IPv4 address associated with the network interface is used as the default route for outgoing traffic.

nmcli connection modify enp3s0 ipv4.never-default true

Add an Ethernet interface to the bridge

nmcli connection add type bridge-slave con-name <interface_name> ifname <physical_interface_name> master <bridge_name> Replace <interface_name> with the desired name for the interface, <physical_interface_name> with the name of the physical interface to be added to the bridge, and <bridge_name> with the name of the bridge.

sudo nmcli con add type bridge-slave ifname enp1s0 master br0

Show details of a bridge

nmcli connection show <bridge_name> Replace <bridge_name> with the name of the bridge to show details of.

Turn on bridge

You must turn off or delete slaved “Wired connection” and turn on br0:

1
2
sudo nmcli con down "Wired connection 1"
sudo nmcli con up br0

When run nmcli show connection, see “br0” and “br0-slave-enp0s25” is deep green. It’s OK.

run brctl show, can see which interfaces connect to bridges.

Set static IP for linux bridge

Determine the name of your bridge interface by running the ip link command. The bridge interface name typically starts with br-, followed by a random string.

Set a static IP address for the bridge connection using the following command:

sudo nmcli connection modify <bridge_connection_name> ipv4.addresses <bridge_ip_address>/<bridge_netmask> ipv4.gateway <bridge_gateway> ipv4.method manual

Replace <bridge_connection_name> with the name of the bridge connection you created in step 2, <bridge_ip_address> with the static IP address you want to assign to the bridge, <bridge_netmask> with the network mask for the bridge, and <bridge_gateway> with the gateway address for your network, if necessary.

For example, if you want to assign the static IP address 192.168.1.100 with a netmask of 255.255.255.0 and no gateway, you can run the following command:

sudo nmcli connection modify br0-connection ipv4.addresses 192.168.52.110/24 ipv4.gateway 192.168.52.1 ipv4.method manual

Save the changes and activate the connection using the following command:

sudo nmcli connection up <bridge_connection_name>

Replace <bridge_connection_name> with the name of the bridge connection you created.

Once the bridge connection is activated, the Linux bridge should be assigned the static IP address you specified.