SoFunction
Updated on 2025-04-08

KVM virtualization Linux Bridge environment deployment method steps

KVM Virtualization Linux Bridge Environment Deployment

This section gives a method for deploying a Linux Bridge bridge environment to connect a virtual machine to the network.

1 Install Linux Bridge

Taking the operation of binding the physical network card Ens33 to Linux Bridge br0 as an example, use the root user to execute the following command to build Linux Bridge:

1.1 Install the bridge-utils package

Linux Bridge is usually managed through the brctl tool, and its corresponding installation package is bridge-utils. The installation command is as follows:

# yum install -y bridge-utils

The example commands are as follows:

[root@superman-21 ~]# yum install -y bridge-utils
Last metadata expiration check: 1 day, 12:32:06 ago on 2023Year02moon05day 星期day 22hour41point25Second.
Dependencies resolved.
============================================================================================================================
 Package                         Architecture              Version                              Repository             Size
============================================================================================================================
Installing:
 bridge-utils                    x86_64                    1.7.1-1.oe2203                       OS                     33 k
​
Transaction Summary
============================================================================================================================
Install  1 Package
​
Total download size: 33 k
Installed size: 62 k
Downloading Packages:
bridge-utils-1.7.1-1.oe2203.x86_64.rpm                                                      186 kB/s |  33 kB     00:00    
----------------------------------------------------------------------------------------------------------------------------
Total                                                                                       179 kB/s |  33 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                    1/1 
  Installing       : bridge-utils-1.7.1-1.oe2203.x86_64                                                                 1/1 
  Running scriptlet: bridge-utils-1.7.1-1.oe2203.x86_64                                                                 1/1 
  Verifying        : bridge-utils-1.7.1-1.oe2203.x86_64                                                                 1/1 
​
Installed:
  bridge-utils-1.7.1-1.oe2203.x86_64                                                                                        
​
Complete!
[root@superman-21 ~]#

1.2 Confirm whether the installation is successful

Confirm whether the bridge-utils component is installed successfully. If the installation is successful, you can view the package-related information.

# rpm -qi bridge-utils

The example commands are as follows:

[root@superman-21 ~]# rpm -iq bridge-utils
bridge-utils-1.7.1-1.oe2203.x86_64
[root@superman-21 ~]# 
[root@superman-21 ~]# rpm -qi bridge-utils
Name        : bridge-utils
Version     : 1.7.1
Release     : 1.oe2203
Architecture: x86_64
Install Date: 2023Year02moon07day Tuesday 11hour13point34Second
Group       : Unspecified
Size        : 63965
License     : GPLv2+
Signature   : RSA/SHA1, 2022Year03moon30day Wednesday 12hour42point49Second, Key ID d557065eb25e7f66
Source RPM  : bridge-utils-1.7.1-1.
Build Date  : 2021Year12moon08day Wednesday 08hour00point00Second
Build Host  : ecs-obsworker-209
Packager    : 
Vendor      : 
URL         : /networking/bridge
Summary     : Utilities for configuring the linux ethernet bridge
Description :
This package provides utilities for configuring the linux ethernet
bridge. The linux ethernet bridge can be used for connecting multiple
ethernet devices together.
[root@superman-21 ~]# 

2 Configuring Linux Bridge

2.1 Create a bridge br0

# brctl addbr br0

The example commands are as follows:

[root@superman-21 ~]# brctl addbr br0
[root@superman-21 ~]# 

View the created bridge br0

# brctl show

The example commands are as follows:

[root@superman-21 ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000000000000       no
[root@superman-21 ~]# 

2.2 Bind physical network card ens33 to Linux Bridge

# brctl addif br0 ens33

The example commands are as follows:

[root@superman-21 ~]# brctl addif br0 ens33
[root@superman-21 ~]# 

Check the configuration of the Linux bridge after binding

Use brctl show to view the current Linux bridge configuration, ens33 has been hung to br0

# brctl show

The example commands are as follows:

[root@superman-21 ~]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000c2996c9d7       no              ens33
[root@superman-21 ~]#

2.3 Configure Ens33's IP

After ens33 is connected to the bridge, the IP address is no longer needed. Set the IP of ens33 to 0.0.0.0.

# ifconfig ens33 0.0.0.0

The example commands are as follows:

[root@superman-21 ~]# ifconfig ens33 0.0.0.0
[root@superman-21 ~]#

2.4 Assign IP to Linux Bridge br0

2.4.1 DHCP settings

If there is a DHCP server, you can set the dynamic IP address through dhclient.

# dhclient br0

The example commands are as follows:

[root@superman-21 ~]# dhclient br0
[root@superman-21 ~]#

Check DHCP to automatically obtain IP address information

# ip add list

The example commands are as follows:

[root@superman-21 ~]# ip add list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 00:0c:29:96:c9:d7 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet6 fe80::9393:f6ae:ced9:7759/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:96:c9:d7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.131/24 brd 192.168.1.255 scope global dynamic br0
       valid_lft 6804sec preferred_lft 6804sec
    inet6 fe80::20c:29ff:fe96:c9d7/64 scope link 
       valid_lft forever preferred_lft forever
[root@superman-21 ~]# 

2.4.2 Static IP settings

If there is no DHCP server, configure static IP for br0, for example, set static IP to 192.168.1.21 and subnet mask to 255.255.255.0.

# ifconfig br0 192.168.1.21 netmask 255.255.255.0

The example commands are as follows:

[root@superman-21 ~]# ifconfig br0 192.168.1.21 netmask 255.255.255.0
[root@superman-21 ~]#

View static IP settings information

# ip add list

The example commands are as follows:

[root@superman-21 ~]# ip add list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 00:0c:29:96:c9:d7 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet6 fe80::9393:f6ae:ced9:7759/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 00:0c:29:96:c9:d7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.21/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe96:c9d7/64 scope link 
       valid_lft forever preferred_lft forever
[root@superman-21 ~]# 

This is the article about the methods and steps for deploying KVM virtualization Linux Bridge environments. For more information about deploying KVM Linux Bridge environments, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!