CentOS 8.1 KVM网桥的配置
KVM的默认网络模式为NAT,借助宿主机模式上网,现在我们来改成桥接模式,这样外界就可以直接和宿主机里的虚拟机通讯了。
Bridge方式即虚拟网桥的网络连接方式,是客户机和子网里面的机器能够互相通信。可以使虚拟机成为网络中具有独立IP的主机。
桥接网络(也叫物理设备共享)被用作把一个物理设备复制到一台虚拟机。网桥多用作高级设置,特别是主机多个网络接口的情况。
KVM网桥模式配置方法如下:
1、查看当前网络信息,其中有两个网卡ens192与ens224
[root@localhost ~]# ifconfig
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::747e:5788:2a5f:e73f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:52:cb:5d txqueuelen 1000 (Ethernet)
RX packets 167 bytes 17983 (17.5 KiB)
RX errors 0 dropped 12 overruns 0 frame 0
TX packets 138 bytes 22400 (21.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.73 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a83b:8933:2e89:c608 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:52:cb:67 txqueuelen 1000 (Ethernet)
RX packets 40 bytes 4737 (4.6 KiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 26 bytes 3642 (3.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 60 bytes 5100 (4.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 5100 (4.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:3b:74:41 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost ~]# nmcli connection #查看当前网络连接命令
NAME UUID TYPE DEVICE
ens192 588802b6-38a5-4d25-927f-753d0509a07d ethernet ens192
ens224 262c71ec-2435-4ad8-8f3f-42a37ddaac7f ethernet ens224
virbr0 02ba45ae-ec2a-4519-a211-08f478ad5a5f bridge virbr0
2、新建网桥,命名为:br0
[root@localhost ~]# nmcli connection add type bridge con-name br0 ifname br0 autoconnect yes
Connection 'br0' (c632af1f-4c0e-4b4f-8a1c-375947ec963b) successfully added. #执行成功提示信息
[root@localhost ~]# nmcli connection #查看新建网桥后连接信息
NAME UUID TYPE DEVICE
br0 c632af1f-4c0e-4b4f-8a1c-375947ec963b bridge br0
ens192 588802b6-38a5-4d25-927f-753d0509a07d ethernet ens192
ens224 262c71ec-2435-4ad8-8f3f-42a37ddaac7f ethernet ens224
virbr0 02ba45ae-ec2a-4519-a211-08f478ad5a5f bridge virbr0
[root@localhost ~]#
3、网桥br0桥接至网卡ens224
[root@localhost ~]# nmcli connection add type bridge-slave ifname ens224 master br0
Connection 'bridge-slave-ens224' (79d21e5f-dee3-438d-809d-2c0ad73455be) successfully added. #执行成功提示信息
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ll
total 16
-rw-r--r-- 1 root root 311 Apr 19 18:05 ifcfg-br0
-rw-r--r-- 1 root root 117 Apr 19 18:10 ifcfg-bridge-slave-ens224 #自动新增的文件
-rw-r--r--. 1 root root 312 Apr 19 17:16 ifcfg-ens192
-rw-r--r--. 1 root root 282 Apr 19 17:22 ifcfg-ens224
[root@localhost network-scripts]# cat ./ifcfg-bridge-slave-ens224 #查看新增文件内容
TYPE=Ethernet
NAME=bridge-slave-ens224
UUID=79d21e5f-dee3-438d-809d-2c0ad73455be
DEVICE=ens224
ONBOOT=yes
BRIDGE=br0
[root@localhost /]#
[root@localhost ~]# nmcli connection #查看当时网络信息,可见新建网桥未启用
NAME UUID TYPE DEVICE
br0 c632af1f-4c0e-4b4f-8a1c-375947ec963b bridge br0
ens192 588802b6-38a5-4d25-927f-753d0509a07d ethernet ens192
ens224 262c71ec-2435-4ad8-8f3f-42a37ddaac7f ethernet ens224
virbr0 02ba45ae-ec2a-4519-a211-08f478ad5a5f bridge virbr0
bridge-slave-ens224 79d21e5f-dee3-438d-809d-2c0ad73455be ethernet --
4、关闭ens224网卡,打开新建br0网桥
[root@localhost ~]# nmcli connection down ens224
Connection 'ens224' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@localhost ~]#
[root@localhost ~]# nmcli connection up br0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@localhost ~]#
[root@localhost ~]# nmcli connection #查看连接(可见新建网桥已经生效)
NAME UUID TYPE DEVICE
ens192 588802b6-38a5-4d25-927f-753d0509a07d ethernet ens192
br0 c632af1f-4c0e-4b4f-8a1c-375947ec963b bridge br0
virbr0 02ba45ae-ec2a-4519-a211-08f478ad5a5f bridge virbr0
bridge-slave-ens224 79d21e5f-dee3-438d-809d-2c0ad73455be ethernet ens224
ens224 262c71ec-2435-4ad8-8f3f-42a37ddaac7f ethernet --
5、查看当前网络信息,新建网桥已经可以使用了。
[root@localhost /]# ifconfig
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.73 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::4700:2f44:285a:c3bc prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:52:cb:67 txqueuelen 1000 (Ethernet)
RX packets 93 bytes 5451 (5.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 45 bytes 7008 (6.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens192: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.63 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::747e:5788:2a5f:e73f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:52:cb:5d txqueuelen 1000 (Ethernet)
RX packets 1695 bytes 176367 (172.2 KiB)
RX errors 0 dropped 12 overruns 0 frame 0
TX packets 1243 bytes 201043 (196.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens224: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:52:cb:67 txqueuelen 1000 (Ethernet)
RX packets 402 bytes 30670 (29.9 KiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 154 bytes 15195 (14.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 144 bytes 12240 (11.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 144 bytes 12240 (11.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:3b:74:41 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
至此,KVM的网桥已经可以使用了,在新建KVM虚拟机是网络选择br0桥接模式即可,如不再使用网桥,可关闭,再重新打开ens224即可。
本文链接:
/archives/kvm-bridge
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
阳光•雨!
喜欢就支持一下吧