CentOS 8 add network bridge (br0) with nmcli command
Tutorial requirements
Requirements
CentOS Linux 8 server
Root privileges
Yes
Difficulty
Easy
Est. reading time
5m
Table of contents
CentOS 8 add network bridge (br0) with nmcli
The procedure to create and add a bridge interface on CentOS 8 is as follows when you want to use Network Manager:
Open the Terminal app or log in using the [nixmcd name=”ssh”]
Find out information about the current CentOS 8 network connection: sudo nmcli con show
Then, add a new bridge called br0: sudo nmcli con add type bridge ifname br0
Create a slave interface for br0: sudo nmcli con add type bridge-slave ifname eno1 master br0
Turn on br0 interface to get an IP via DHCP: sudo nmcli con up br0
Static IP settings are discussed below for the br0 interface
Let us see all examples and instructions in detail to create a network bridge in CentOS 8.
Warning : These instructions make critical network changes to your existing server, and wrong commands might lose network/ssh connectivity to the server. Hence, running these commands over ssh based sessions not recommended. Further, you may need to update firewall rules to match the network bridge settings. For remote servers, I recommend using KVM over IP or IPMI based remote sessions.
No ads and tracking
In-depth guides for developers and sysadmins at Opensourceflare✨
Join my Patreon to support independent content creators and start reading latest guides:
How to set up Redis sentinel cluster on Ubuntu or Debian Linux
How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Prerequisite to create a Linux Network Bridge on CentOS 8
First thing, obtain information about the current CentOS Linux 8 interface and IP address as we need this information later. Hence, type the following command: $ nmcli con show $ nmcli connection show —active Outputs:
So my server has an “eno1” which uses the eno1 Ethernet interface. I am going to set up a bridge interface named br0 and add (enslave) an interface to eno1.
Step 1 – Create a network bridge named br0
The syntax is: $ sudo nmcli con add ifname br0 type bridge con-name br0 $ sudo nmcli con add type bridge-slave ifname eno1 master br0 $ nmcli connection show
Step 2 – Disable or enable STP for network bridge
The primary purpose of Spanning Tree Protocol (STP) is to ensure that you do not create loops when you have redundant paths in your network. We can disable STP or enable as follows for br0: $ sudo nmcli con modify br0 bridge.stp no ## CentOS 8 nmcli command to enable STP with br0 ## $ sudo nmcli con modify br0 bridge.stp yes ## Verification ## $ nmcli con show $ nmcli -f bridge con show br0 Outputs:
Step 3 – Set up static or DHCP based IP for network bridge interface
We have not allocated any static IP address to our br0 interface. Hence, if the DHCP server is available, it should provide IP addresses and other settings. However, on servers, we typically set up a static IP address. In this example, I am converting existing eno1 IP network settings to br0 settings as follows:
So far, we configured required network settings. It is time to turn it on our br0: $ sudo nmcli con up br0 $ nmcli con show Wait for some time to activate settings.
Step 5 – Verification network bridge settings
Use the ip command to view the IP settings for br0: $ ip a s $ ip a s br0 You can remove eno1 as br0 got a static IP address itself as eno1 will be in forwarding state: $ sudo nmcli connection delete eno1 Here is how it looks using the ip command: $ nmcli connection show $ ip a show br0 $ nmcli device ## interface active and works with br0 ## $ ip a show eno1 $ ip r ## Check Internet and local LAN connectivity using ping command ## $ ping -c 4 www.cyberciti.biz $ ping -c 4 192.168.2.25 Show the link status of Ethernet devices and bridge devices on CentOS 8 Linux machine: $ ip link show master br0 $ bridge link show $ bridge link show dev eno1
Conclusion
In this tutorial, you learned how to add and create a Linux Network Bridge on CentoS 8 server. See nmcli docs here for more info.
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
How to create or configure network bridge in CentOS / RHEL 7/8
Table of Contents
In my last article I shared the steps to configure NIC Teaming on RHEL/CentOS 7 Linux . In this article I will show you step by step guide to configure network bridge using nmtui (NetworkManager) on CentOS or RHEL 7 node. A network bridge is a Link Layer device which forwards traffic between networks based on MAC addresses and is therefore also refer to as a Layer 2 device. Bridge networking (also known as network bridging or virtual network switching) will place virtual machine network interfaces on the same network as the physical interface.
You can configure network bridge using NetworkManager Text User Interface (NMTUI) or via Command Line Interface (CLI) by manually creating the required configuration files. I have written another article to configure network bridge on Oracle Virtual Box .
Configure Network Bridge using NMTUI (NetworkManager)
The text user interface tool nmtui can be used to configure network bridge in a terminal window. Issue the following command to start the tool:
The text user interface appears. Any invalid command prints a usage message.
From the starting menu, select Edit a connection. Select Add, the New Connection screen opens.
Select Bridge using which you wish to configure network bridge, the Edit connection screen opens.
Give a Profile name and Device name to the bridge.
To add slave interfaces to the bridge select Add, the New Connection screen opens.
Enter the required slave’s device name or MAC address in the Device section and select the OK button.
The name of the bridge slave appears in the Slaves section.
If you have a DHCP server then you can leave the IPv4 and IPv6 Address set to «Automatic«. If you wish to assign static IP then manually fill in the network details as shown below. Since we are not using IPv6 so I have set IPv6 Configuration as Ignore.
Review and confirm the settings before selecting the OK button which will exit the nmtui (NetworkManager) utility..
Next restart your network services for the changes to take affect.
Now check your network configuration
Finally now we will validate our bridge connectivity
So we can connect to our gateway which means our bridge is working as expected.
Configure network bridge via CLI
To configure network bridge, create a file in the /etc/sysconfig/network-scripts/ directory called ifcfg-brN , replacing N with the number for the interface, such as 0. For our case we will create ifcfg-br1
The contents of the bridge interface file and ethernet interface file is almost. The differences in this example are as follows:
The DEVICE directive is given an interface name as its argument in the format brN , where N is replaced with the number of the interface.
The TYPE directive is given an argument Bridge. This directive determines the device type and the argument is case sensitive.
The bridge interface configuration file now has the IP address and the physical interface has only a MAC address.
An extra directive, DELAY=0 , is added to prevent the bridge from waiting while it monitors traffic, learns where hosts are located, and builds a table of MAC addresses on which to base its filtering decisions.
Add NM_CONTROLLED=no to the Ethernet interface to prevent NetworkManager from altering the file.
The following is a sample bridge interface configuration file using a static IP address:
To complete network bridge we must create another interface, or you can use an existing interface, and point it to the bridge interface. The following is a sample Ethernet interface configuration file pointing to a bridge interface. Configure your physical interface in /etc/sysconfig/network-scripts/ifcfg-ethX , where X is a unique number corresponding to a specific interface, as follows:
Finally restart your network service for the changes to take affect
I hope the article to configure network bridge using NetworkManager nmtui on RHEL/CentOS 7/8 Linux was useful. Please let me know your feedback and views using the comment box below.
Related Posts
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.
For any other feedbacks or questions you can either use the comments section or contact me form.
Thank You for your support!!
Источник
3 Ways to Create a Network Bridge in RHEL/CentOS 8
A network bridge is a data-link layer device that interconnects two or more network segments, offering communication between them. It creates a single network interface to set up a single aggregate network from multiple networks or network segments. It forwards traffic based on the MAC addresses of hosts (stored in a MAC address table).
Linux operating systems such as RHEL (Red Hat Enterprise Linux) and CentOS 8 support the implementation of a software-based network bridge to emulate a hardware bridge. The bridge serves a similar function as a network switch; it acts more or less like a virtual network switch.
There are several use cases of network bridging, one practical application is in a virtualization environment to create a virtual network switch used to connect virtual machines (VMs) to the same network as the host.
This guide shows multiple ways to set up a network bridge in RHEL/CentOS 8 and use it to set up virtual networking in a bridged mode under Oracle VirtualBox and KVM, to connect Virtual Machines to the same network as the host.
On this page:
Setting Up a Network Bridge Using nmcli Tool
nmcli is a widely-used, scriptable and powerful command-line tool to control NetworkManager and report network status. It communicates directly to NetworkManager and controls only system-wide connections. Importantly, it allows users to use abbreviations, as long as they are a unique prefix in the set of possible options.
First, use the IP command to identify the network interfaces (both physical and virtual) currently attached to your machine and the networks they are connected to.
From the output of the above command, the Ethernet interface is called enp2s0, we will add this interface to the bridge as a slave.
Check Network Interfaces
Next, to list the active network connections on the test system, use the following nmcli command.
List Active Network Connections
Important: If the libvirtd daemon (libvirtd) is installed and started, the default network interface that represents the network bridge (virtual network switch) is virbr0 as seen in the above screenshots. It is configured to run in NAT mode.
Next, create a network bridge interface using the following nmcli command, where conn or con stands for connection, and the connection name is br0 and the interface name is also br0.
Create Network Bridge Interface
Note: In a bridged mode, the virtual machines are easily accessible to the physical network, they appear within the same subnet as the host machine and they can access services such as DHCP.
To set a static IP address, run the following commands to set IPv4 address, network mask, default gateway, and DNS server of the br0 connection (set the values according to your environment).
Now add the Ethernet interface (enp2s0) as a portable device to the bridge (br0) connection as shown.
Add Ethernet Interface as a Slave to Bridge
Next, bring up or activate the bridge connection, you can use the connection name or UUID as shown.
Active Network Bridge Connection
Then deactivate or bring down the Ethernet or Wired connection.
De-active Network Wired Connection
Now when you try to list the active network connections on the system, the bridge connection should display on the list.
List Active Network Connection
Next, use the following bridge command to display the current bridge port configuration and flags.
Show Bridge Ports
To deactivate the bridge connection and delete it, run the following commands. Note that you first of all have to activate the wired connection.
Delete Bridge Network Connection
For more information, see the nmcli manual page.
Creating a Network Bridge via Cockpit Web Console
The cockpit is a lightweight, interactive and easy-to-use web-based server administration interface. To interact with the system’s network configuration, the cockpit uses NetworkManager and the DBus APIs it provides.
To add a bridge, go to Networking, then click Add Bridge as highlighted in the following image.
Choose Networking in Cockpit Web Console
A pop window with options to add a new bridge will appear. Set the bridge name and select the ports as shown in the following screenshot. You can optionally enable STP (Spanning Tree Protocol) and then click Apply.
Add Network Bridge Settings
Under the list of Interfaces, the new bridge should now appear and the Ethernet interface should be de-activated.
New Network Bridge Interface
To view the bridge in detail, double click on it. There are options to take it down or delete, add a new port device to it and more.
View Network Bridge Details
Creating a Network Bridge Using nm-connection-editor Application
nm-connection-editor is a graphical network connection editor for NetworkManager, used to add, remove, and modify network connections stored by NetworkManager. Any modifications can only work if NetworkManager is running.
To launch it, run the nm-connection-editor command as root in the command line or open it from the system menu.
Once it opens up, click the plus sign to add a new connection as highlighted in the following screenshot.
Add a New Network Connection
From the pop window, choose the connection type from the drop-down, Bridge in this case and click Create.
Choose Network Connection Type
Next, set a bridge connection and interface name, then click Add to add a bridge port. Choose Ethernet as the connection type. Then click Create.
Create a Bridge Connection Choose Ethernet as Connection Type
Next, edit the port device connection details and click Save.
Edit Network Bridge Port
Now the bridged port should be added to the list of bridged connections. Then click Save.
Network Bridge Port Added
From the connection editor’s main interface, you should be able to see the new bridged connection and bridge interface as shown in the following screenshot.
Network Bridge Created Successfully
Now go ahead to activate the bridge connection and deactivate the wired connection from the command line using the nmcli tool as shown before.
How to Use the Network Bridge in a Virtualization Software
In this section, we will show how to use a bridge to connect virtual machines to the host network, under Oracle VirtualBox and KVM as explained below.
Using a Network Bridge in Oracle VirtualBox
To configure a virtual machine to use a bridged adapter, select it from the list of VMs, then go to its settings, click Network option and select the adapter (e.g Adapter 1), then make sure the Enable Network Adapter option is checked, set the attached to as Bridged Adapter, then select the name of the bridged interface (br0) and click Ok.
Configure VM to Use Bridge Network in VirtualBox
Using a Network Bridge in KVM
To use the network bridge created above under KVM, use the —network=bridge=br0 option while virtual machines using the command-line interface, using the virt-install command.
You can as well create additional networks and configure them using the virsh command-line tool, and a VM’s XML configuration file can be edited to use one of these new bridged networks.
In this guide, we have shown how to set up a network bridge in RHEL/CentOS 8 and use it within to connect VMs to the same network of the host, under Oracle VirtualBox and KVM.
As usual, reach us via the feedback form below for any questions or comments. You can find more details in understanding virtual networking and configuring a network bridge in RHEL 8 documentation.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.