目錄
- KVM虛擬化Linux Bridge環(huán)境部署
- 1 安裝Linux Bridge
- 1.1 安裝bridge-utils軟件包
- 1.2 確認(rèn)安裝是否成功
- 2 配置Linux Bridge
- 2.1 創(chuàng)建網(wǎng)橋br0
- 2.2 將物理網(wǎng)卡ens33綁定到Linux Bridge
- 2.3 配置ens33的ip
- 2.4 為L(zhǎng)inux Bridge網(wǎng)橋br0分配ip
KVM虛擬化Linux Bridge環(huán)境部署
本節(jié)給出Linux Bridge網(wǎng)橋環(huán)境部署的方法,使虛擬機(jī)連接到網(wǎng)絡(luò)。
1 安裝Linux Bridge
以物理網(wǎng)卡ens33綁定到Linux Bridge br0的操作為例,使用root用戶執(zhí)行如下命令搭建Linux Bridge :
1.1 安裝bridge-utils軟件包
Linux Bridge通常通過(guò)brctl工具管理,其對(duì)應(yīng)的安裝包為bridge-utils,安裝命令如下:
# yum install -y bridge-utils
示例命令如下:
[root@superman-21 ~]# yum install -y bridge-utils Last metadata expiration check: 1 day, 12:32:06 ago on 2023年02月05日 星期日 22時(shí)41分25秒. 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 確認(rèn)安裝是否成功
確認(rèn)bridge-utils組件是否安裝成功若安裝成功,可以查看軟件包相關(guān)信息。
# rpm -qi bridge-utils
示例命令如下:
[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: 2023年02月07日 星期二 11時(shí)13分34秒 Group : Unspecified Size : 63965 License : GPLv2+ Signature : RSA/SHA1, 2022年03月30日 星期三 12時(shí)42分49秒, Key ID d557065eb25e7f66 Source RPM : bridge-utils-1.7.1-1.oe2203.src.rpm Build Date : 2021年12月08日 星期三 08時(shí)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 ~]#
2 配置Linux Bridge
2.1 創(chuàng)建網(wǎng)橋br0
# brctl addbr br0
示例命令如下:
[root@superman-21 ~]# brctl addbr br0 [root@superman-21 ~]#
查看創(chuàng)建的網(wǎng)橋br0
# brctl show
示例命令如下:
[root@superman-21 ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@superman-21 ~]#
2.2 將物理網(wǎng)卡ens33綁定到Linux Bridge
# brctl addif br0 ens33
示例命令如下:
[root@superman-21 ~]# brctl addif br0 ens33 [root@superman-21 ~]#
查看綁定后Linux網(wǎng)橋的配置
用brctl show查看當(dāng)前Linux網(wǎng)橋的配置,ens33已經(jīng)掛到br0上了
# brctl show
示例命令如下:
[root@superman-21 ~]# brctl show bridge name bridge id STP enabled interfaces br0 8000.000c2996c9d7 no ens33 [root@superman-21 ~]#
2.3 配置ens33的ip
ens33與網(wǎng)橋連接后,不再需要 IP 地址,將ens33的IP設(shè)置為0.0.0.0。
# ifconfig ens33 0.0.0.0
示例命令如下:
[root@superman-21 ~]# ifconfig ens33 0.0.0.0 [root@superman-21 ~]#
2.4 為L(zhǎng)inux Bridge網(wǎng)橋br0分配ip
2.4.1 DHCP設(shè)置
如果有DHCP服務(wù)器,可以通過(guò)dhclient設(shè)置動(dòng)態(tài)IP地址。
# dhclient br0
示例命令如下:
[root@superman-21 ~]# dhclient br0 [root@superman-21 ~]#
查看dhcp自動(dòng)獲取ip地址信息
# ip add list
示例命令如下:
[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 靜態(tài)ip設(shè)置
如果沒(méi)有DHCP服務(wù)器,給br0配置靜態(tài)IP,例如設(shè)置靜態(tài)IP為192.168.1.21,子網(wǎng)掩碼為255.255.255.0。
# ifconfig br0 192.168.1.21 netmask 255.255.255.0
示例命令如下:
[root@superman-21 ~]# ifconfig br0 192.168.1.21 netmask 255.255.255.0 [root@superman-21 ~]#
查看靜態(tài)ip設(shè)置后信息
# ip add list
示例命令如下:
[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 ~]#