3 Ways to Create a Network Bridge in RHEL CentOS 8


A network bridge is a software component that allows multiple networks to be connected together, creating a larger network that can be used to share resources and communicate between devices. In Red Hat Enterprise Linux (RHEL) and CentOS 8, network bridging can be achieved in several ways, depending on your needs and preferences.

In this article, we will explore three ways to create a network bridge in RHEL/CentOS 8, using examples and step-by-step instructions. Whether you need to connect virtual machines or physical devices, these methods will help you set up a bridge that meets your requirements.

Method 1: Using nmcli command line tool

The nmcli command line tool is a powerful utility for managing network connections in RHEL/CentOS 8. It can be used to create, modify, and delete network connections, including network bridges. Here's how to use nmcli to create a network bridge −

  • Step 1 − Check network interfaces

Before creating a network bridge, you need to identify network interfaces that you want to bridge. You can use following command to list all available network interfaces on your system −

nmcli device status

This command will show a list of network interfaces, along with their connection status and device type.

  • Step 2 − Create a new bridge connection

To create a new bridge connection, use following command −

sudo nmcli connection add type bridge ifname br0

This command creates a new bridge connection with name br0. You can replace br0 with any name you prefer. Note that this command does not assign any network interfaces to bridge yet.

  • Step 3 − Add network interfaces to bridge

To add network interfaces to bridge, use following command −

sudo nmcli connection add type bridge-slave ifname eth0 master br0

Replace eth0 with name of network interface you want to add to bridge. You can add multiple network interfaces to bridge by running this command multiple times, changing interface name each time.

  • Step 4 − Activate bridge connection

To activate bridge connection, use following command −

sudo nmcli connection up br0

This command will bring up bridge connection and activate it. Now, any device connected to network interfaces that you added to bridge will be able to communicate with other devices on same network.

Method 2: Using NetworkManager GUI

If you prefer a graphical user interface (GUI) over command line, you can use NetworkManager GUI to create a network bridge in RHEL/CentOS 8. Here's how to do it −

  • Step 1 − Open NetworkManager GUI

Open NetworkManager GUI by clicking on network icon in system tray, then selecting "Network Settings" option.

  • Step 2 − Create a new bridge connection

In NetworkManager GUI, click on "+" button to add a new connection. Select "Bridge" option and click "Create".

  • Step 3 − Configure bridge connection

In bridge connection settings, give bridge a name (such as br0) and select network interfaces that you want to add to bridge. You can also configure other settings, such as IP address and DNS servers, if needed.

  • Step 4 − Activate bridge connection

Click on toggle button to activate bridge connection. Now, any device connected to network interfaces that you added to bridge will be able to communicate with other devices on same network.

Method 3: Using firewalld network zone

If you want to create a network bridge that is also protected by a firewall, you can use firewalld network zone feature in RHEL/CentOS 8.

Here's how to use firewalld to create a network bridge −

  • Step 1 − Check network interfaces

As in method 1, you need to identify network interfaces that you want to bridge. Use following command to list all available network interfaces −

nmcli device status
  • Step 2 − Create a new network zone

To create a new network zone that includes bridge, use following command −

sudo firewall-cmd --permanent --new-zone=brzone

This command creates a new network zone called brzone. You can replace brzone with any name you prefer.

  • Step 3 − Add bridge to new zone

To add bridge to new network zone, use following command −

sudo firewall-cmd --permanent --zone=brzone --add-interface=br0

This command adds bridge connection (br0) to brzone network zone.

  • Step 4 − Configure firewall rules for new zone

To configure firewall rules for new network zone, use following commands −

sudo firewall-cmd --permanent --zone=brzone --add-service=http
sudo firewall-cmd --permanent --zone=brzone --add-service=https

These commands add http and https services to brzone network zone. You can add other services or ports as needed.

  • Step 5 − Reload firewalld

After configuring firewall rules, reload firewalld to apply changes −

sudo firewall-cmd --reload

Now, any device connected to network interfaces that you added to bridge (and assigned to brzone network zone) will be protected by firewall and able to communicate with other devices on same network.

Method 4: Using network-scripts

Another way to create a network bridge in RHEL/CentOS 8 is by using network-scripts. This method involves manually editing configuration files to create bridge and assign network interfaces to it. While it may be more complex than previous methods, it also provides greater control and flexibility over bridge configuration.

  • Step 1 − Install bridge-utils

Before you can create a bridge using network-scripts, you need to install bridge-utils package. Use following command to install it −

sudo dnf install bridge-utils
  • Step 2 − Edit ifcfg files

The ifcfg files are used by network-scripts to configure network interfaces. To create a bridge, you need to edit ifcfg files for network interfaces that you want to bridge and create a new ifcfg file for bridge itself.

First, make a backup of original ifcfg files −

sudo cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.backup
sudo cp /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth1.backup

Then, create a new ifcfg file for bridge −

sudo vi /etc/sysconfig/network-scripts/ifcfg-br0

Add following lines to file −

makefile
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
ONBOOT=yes

Replace IP address, netmask, and gateway with values appropriate for your network.

Next, edit ifcfg files for network interfaces that you want to bridge. For example, to bridge eth0 and eth1, edit files as follows −

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0

Add following lines to file −

makefile
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0

Repeat process for eth1 −

sudo vi /etc/sysconfig/network-scripts/ifcfg-eth1

Add following lines to file −

makefile
DEVICE=eth1
ONBOOT=yes
BRIDGE=br0
  • Step 3 − Restart network-scripts

After editing ifcfg files, restart network-scripts service to apply changes −

sudo systemctl restart NetworkManager.service

Now, bridge should be up and running, connecting network interfaces that you specified. You can verify status of bridge using following command −

sudo brctl show

This command shows status of all bridges on system. output should include a line for br0, indicating that bridge is active and connected to specified network interfaces.

Conclusion

In RHEL/CentOS 8, there are several ways to create a network bridge, depending on your needs and preferences. You can use nmcli command line tool, NetworkManager GUI, or firewalld network zone feature to create a bridge that connects multiple networks and devices together.

Regardless of which method you choose, it is important to carefully configure bridge and any related settings, such as firewall rules and IP addresses, to ensure that it functions properly and securely. With these methods, you can create a network bridge that meets your requirements and enables effective communication and resource sharing between devices on your network.

Updated on: 28-Mar-2023

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements