How To Create a Linux Network Bridge on RHEL 8 / CentOS 8

Posted on 107 views

How can I create a Linux network bridge on RHEL 8 / CentOS 8 Linux system?. In today’s tutorial, we will look at how to create a Linux Bridge on RHEL 8 / CentOS 8 server. In Linux networking, a bridge is used to connect two or more network segments. It is commonly used in Virtualization to pass Virtual Machines traffic through a hypervisor network card. All guest machines connected to a network bridge will treat it transparently as a physical network interface.

Linux bridge behaves like a virtual network switch and any physical or virtual device can be connected to the bridge. This article explains how to create a network bridge comprising of at least one ethernet device.

Create Linux Network Bridge on RHEL 8 / CentOS 8 with nmcli

Below are the steps used to create a Linux Network Bridge on RHEL / CentOS 8 server. with nmcli.

Step 1: Create a Linux Bridge

Use the nmcli network management command line tool to create a Linux bridge on a desired interface. Let’s list available connections.

$ sudo nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
enp1s0              498869bb-0d88-4a4c-a83a-c491d1040b0b  ethernet  enp1s0 
Wired connection 1  0977f29f-fa2e-3d7f-831c-6f41f8782be3  ethernet  enp7s0 

Since my bridge will be created on the second device enp7s0, I’ll delete the existing connection then create bridge with this device.

$ sudo nmcli connection delete 0977f29f-fa2e-3d7f-831c-6f41f8782be3
Connection 'Wired connection 1' (0977f29f-fa2e-3d7f-831c-6f41f8782be3) successfully deleted.

1. Save bridge related information to variables.

BR_NAME="br0"
BR_INT="enp7s0"
SUBNET_IP="192.168.122.10/24"
GW="192.168.122.1"
DNS1="8.8.8.8"
DNS2="8.8.4.4"

Where:

  • BR_NAME: The name of the bridge to be created.
  • BR_INT: the physical network device to be used as bridge slave.
  • SUBNET_IP: IP address and subnet assigned to the bridge created.
  • GW: The IP address of the default gateway
  • DNS1 and DNS2: IP addresses of DNS servers to be used.

2. Define new bridge connection.

sudo nmcli connection add type bridge autoconnect yes con-name $BR_NAME ifname $BR_NAME

Output:

Connection 'br0' (be6d4520-0257-49c6-97c2-f515d6554980) successfully added.

3. Modify bridge to add IP address, Gateway and DNS

sudo nmcli connection modify $BR_NAME ipv4.addresses $SUBNET_IP ipv4.method manual
sudo nmcli connection modify $BR_NAME ipv4.gateway $GW
sudo nmcli connection modify $BR_NAME ipv4.dns $DNS1 +ipv4.dns $DNS2

4. Add the network device as bridge slave.

sudo nmcli connection delete $BR_INT
sudo nmcli connection add type bridge-slave autoconnect yes con-name $BR_INT ifname $BR_INT master $BR_NAME

Sample output.

Connection 'enp7s0' (f033dbc9-a90e-4d4c-83a9-63fd7ec1cdc1) successfully added.

Check connections.

$ sudo nmcli connection show 
NAME    UUID                                  TYPE      DEVICE 
br0     be6d4520-0257-49c6-97c2-f515d6554980  bridge    br0    
enp1s0  498869bb-0d88-4a4c-a83a-c491d1040b0b  ethernet  enp1s0 
enp7s0  f033dbc9-a90e-4d4c-83a9-63fd7ec1cdc1  ethernet  enp7s0 

Step 2: Bring up network bridge

Once the network bridge connection has been created, bring it up.

$ sudo nmcli connection up br0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

View bridge details by running.

sudo nmcli connection show br0

The ip addr command should give output similar to below.

$ ip ad
3: enp7s0:  mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
     link/ether 52:54:00:a2:f6:a8 brd ff:ff:ff:ff:ff:ff
 4: br0:  mtu 1500 qdisc noqueue state UP group default qlen 1000
     link/ether 52:54:00:a2:f6:a8 brd ff:ff:ff:ff:ff:ff
     inet 192.168.122.10/24 brd 192.168.122.255 scope global noprefixroute br0
        valid_lft forever preferred_lft forever
     inet6 fe80::4f2f:ce6d:dc6b:2101/64 scope link noprefixroute 
        valid_lft forever preferred_lft forever

The bridge is active and now ready for use. You can learn how to use a Linux network bridge on Using KVM on RHEL / CentOS 8.

Create a Linux Network Bridge on RHEL 8 / CentOS 8 manually

It is also possible to create a Linux network bridge by manually creating network configuration scripts on RHEL / CentOS 8 server.

Bridge Network Configuration.

$ cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
DELAY=0
STP=off
ONBOOT=yes
IPADDR=192.168.122.10
NETMASK=255.255.255.0
GATEWAY=192.168.122.1
BOOTPROTO=none
DEFROUTE=yes
NM_CONTROLLED=no
IPV6INIT=no
DNS1=192.168.122.1
DNS2=8.8.8.8

Interface configuration file.

$ cat /etc/sysconfig/network-scripts/ifcfg-enp7s0
DEVICE=enp7s0
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0

Reboot your system to confirm that bridging is working.

sudo reboot

Once rebooted, verify your settings using the ip command.

sudo ip addr

Thanks for using our guide to create and configure Linux network bridge on RHEL / CentOS 8. You can also check our guide on how to add a secondary IP address to a RHEL / CentOS network interface.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.