This section gives the method of deploying Linux Bridge network bridge environment to connect the virtual machine to the network.
5.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
5.1.1 Install 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
Example commands are as follows:
[root@superman-21 ~]# yum install -y bridge-utils Last metadata expiration check: 1 day, 12:32:06 ago on Sunday, February 5, 2023 22:41:25. Dependencies resolved. ================================================== ================================================== ======================== Package Architecture Version Repository Size ================================================== ================================================== ======================== Installing: bridge-utils x86_64 1.7.1-1.oe2203 OS 33k ? Transaction Summary ================================================== ================================================== ======================== Install 1 Package ? Total download size: 33k Installed size: 62k 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 ~]#
5.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 related information of the software package.
# rpm -qi bridge-utils
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: Tuesday, February 07, 2023 11:13:34 Group: Unspecified Size: 63965 License: GPLv2+ Signature: RSA/SHA1, Wednesday, March 30, 2022 12:42:49, Key ID d557065eb25e7f66 Source RPM: bridge-utils-1.7.1-1.oe2203.src.rpm Build Date: Wednesday, December 08, 2021 08:00:00 Build Host: ecs-obsworker-209 Packager: http://openeuler.org Vendor: http://openeuler.org URL: https://wiki.linuxfoundation.org/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 ~]#
5.2 Configure Linux Bridge
5.2.1 Create bridge br0
# brctl addbr br0
Example commands are as follows:
[root@superman-21 ~]# brctl addbr br0 [root@superman-21 ~]#
View the created bridge br0
# brctl show
Example commands are as follows:
[root@superman-21 ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@superman-21 ~]#
5.2.2 Bind the physical network card ens33 to Linux Bridge
# brctl addif br0 ens33
Example commands are as follows:
[root@superman-21 ~]# brctl addif br0 ens33 [root@superman-21 ~]#
View the configuration of the Linux bridge after binding
Use brctl show to check the current Linux bridge configuration. ens33 has been linked to br0.
# brctl show
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 ~]#
5.2.3 Configure ens33 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
Example commands are as follows:
[root@superman-21 ~]# ifconfig ens33 0.0.0.0 [root@superman-21 ~]#
5.2.4 Assign ip to Linux Bridge br0
5.2.4.1 DHCP Settings
If you have a DHCP server, you can set a dynamic IP address through dhclient.
#dhclientbr0
Example commands are as follows:
[root@superman-21 ~]# dhclient br0 [root@superman-21 ~]#
Check dhcp to automatically obtain ip address information
# ip add list
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 ~]#
5.2.4.2 Static IP settings
If there is no DHCP server, configure a static IP for br0, for example, set the static IP to 192.168.1.21 and the subnet mask to 255.255.255.0.
# ifconfig br0 192.168.1.21 netmask 255.255.255.0
Example commands are as follows:
[root@superman-21 ~]# ifconfig br0 192.168.1.21 netmask 255.255.255.0 [root@superman-21 ~]#
View information after static IP setting
# ip add list
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 ~]#
The knowledge points of the article match the official knowledge files, and you can further learn relevant knowledge. CS entry skill treeLinux introductionFirst introduction to Linux 37639 people are learning the system