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

0
517

In this tutorial, you’ll cover the creation of Linux Network Bridge on CentOS / RHEL 8. As you know Bridge is used to connect two or more roads, Similarly here in Linux Bridge is used to connect two or more segments together. The common use of Linux Network Bridge is to pass the Virtual Machines traffic through a hyper visor network card. By doing so all machines connected to a network bridge will act as a physical network interface.

Creating a Linux Network Bridge on CentOS 8 / RHEL 8 using nmcli

Network bridge behaves as a virtual network switch. We’ll proceed further to see how it can be created and used follow the below steps to get started.

Step 1: Creating a Linux Bridge

Here we will use the nmcli network management command line tool to create a Linux bridge on a desired interface.

To see connections available run the following command.

$ sudo nmcli connection show
NAME UUID TYPE DEVICE
ens33 8806158c-9c2b-4ffb-8109-8b662baf8581 ethernet ens33
virbr0 06282371-27ba-4f03-b3c5-ebcc401e2531 bridge virbr0
virbr0-nic 0dcb669a-5ead-4a67-a877-2f78d432691e tun virbr0-nic
ens33 93392eb5-c75b-45ea-80a3-509e01144dc7 ethernet --
ens33 2a10fc64-1312-4232-8103-5cdc114cf5b8 ethernet --

As my bridge will be created on the second device ens33 So, I’ll delete the existing connection to create a bridge connection with this device.

$ sudo nmcli connection delete ens33
[[email protected] root]$ sudo nmcli connection delete ens33
Connection 'ens33' (93392eb5-c75b-45ea-80a3-509e01144dc7) successfully deleted.
Connection 'ens33' (2a10fc64-1312-4232-8103-5cdc114cf5b8) successfully deleted.
Connection 'ens33' (8806158c-9c2b-4ffb-8109-8b662baf8581) successfully deleted.

Now save bridge related information to variables.

BR_NAME="ifname"
BR_INT="ens29"
SUBNET_IP="192.168.94.10/24"
GW="192.168.94.1"
DNS1="8.8.8.8"
DNS2="8.8.4.4"
  • BR_NAME: Name of the bridge, we are going to create.
  • BR_INT: Physical device to be used as a bridge slave.
  • SUBNET_IP: IP address & subnet assigned to the created bridge.
  • GW: Default Gateway address.
  • DNS1 & DNS2: DNS servers IP which are to be used.

Now after assigning information, create new bridge connection.

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

You will see the following output upon successful creation.

Connection 'ifname' (f76df2f2-f4ed-48a3-b39d-e58979710298) successfully added.

After creating connection of bridge assign the IP address, Gateway and DNS servers.

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}

Now add the network device as a 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}

Output:

Connection 'ifname' (f76df2f2-f4ed-48a3-b39d-e58979710298) successfully added.

Run the following command to check connection changes.

sudo nmcli connection show

You’ll see the bridge connection you’ve just created.

NAME        UUID                                  TYPE      DEVICE
ens33 dde2beed-2e9d-4ea8-82c6-460306f17847 ethernet ens33
virbr0 06282371-27ba-4f03-b3c5-ebcc401e2531 bridge virbr0
virbr0-nic 0dcb669a-5ead-4a67-a877-2f78d432691e tun virbr0-nic
ifname f76df2f2-f4ed-48a3-b39d-e58979710298 bridge nm-bridge
ifname 984edc85-9e75-45b1-843b-e06d11631cae bridge nm-bridge1

Step 2: Bring up Network Bridge

Now it’s time to bring up the network bridge after creating successful connection.

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

You can view bridge details by running

sudo nmcli connection show ifname

To find out IP address run the following command .

$ ip ad

That’s it! The bridge is now ready to use.

If have any queries regarding this tutorial, feel free to ask!

LEAVE A REPLY

Please enter your comment!
Please enter your name here