KVM网桥

原创
2019/01/04 10:53
阅读数 611

安装KVM的虚拟机重新启动后,网桥就出现了问题,内部创建的虚拟机采用NAT可以联网,但是bridge的形式就失败了。

一、问题描述

已经配置好的虚拟机地址出现不能联网的,重启网络失败,不能DHCP获取IP,换成NAT模式可以联网。

 

二、排查步骤

2.1 检查宿主机网桥状态

[root@localhost data]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.fe5400f102b0       no              vnet0
virbr0          8000.525400caea1a       yes             virbr0-nic

由上可以看到 br0 网桥连接的端口变成了 vnet0。

 

2.2 查看网卡信息

查看网卡信息可以看到 br0 的 ether 值已经和 vnet0 一致,事实上 br0 的 ether 值应与 ens33 一致。

[root@localhost data]# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.87  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::fc54:ff:fef1:2b0  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:f1:02:b0  txqueuelen 1000  (Ethernet)
        RX packets 511  bytes 22864 (22.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17  bytes 2059 (2.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.87  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::2d06:9771:731e:bf23  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:28:6e:6d  txqueuelen 1000  (Ethernet)
        RX packets 5292  bytes 1433754 (1.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1099  bytes 132355 (129.2 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 79  bytes 6877 (6.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 79  bytes 6877 (6.7 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:ca:ea:1a  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

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fef1:2b0  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:f1:02:b0  txqueuelen 1000  (Ethernet)
        RX packets 309  bytes 21246 (20.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9  bytes 737 (737.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

2.3 删除网桥重启网络

在删除 br0 网桥之前,我们先停止该网卡,然后删除该网卡对应的网桥。

[root@localhost network-scripts]# ifconfig br0 down
[root@localhost network-scripts]# brctl delbr br0
[root@localhost network-scripts]# 
[root@localhost network-scripts]# brctl show
bridge name     bridge id               STP enabled     interfaces
virbr0          8000.525400caea1a       yes             virbr0-nic

分别查看 br0 和 ens33 的网卡配置文件信息,确认无误后,重启网络。

[root@localhost network-scripts]# /etc/init.d/network restart
Restarting network (via systemctl):  [  确定  ]

查看网桥状态,可以看到 br0 已经连接上 ens33。

[root@localhost network-scripts]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000c29286e6d       no              ens33
virbr0          8000.525400caea1a       yes             virbr0-nic

网卡信息的状态也已经正常, br0 的 ether 值已和 ens33 的 ether 一致。

[root@localhost network-scripts]# ifconfig 
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.87  netmask 255.255.0.0  broadcast 192.168.255.255
        inet6 fe80::20c:29ff:fe28:6e6d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:28:6e:6d  txqueuelen 1000  (Ethernet)
        RX packets 8130  bytes 906360 (885.1 KiB)
        RX errors 0  dropped 34  overruns 0  frame 0
        TX packets 274  bytes 30942 (30.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:0c:29:28:6e:6d  txqueuelen 1000  (Ethernet)
        RX packets 78069  bytes 63006695 (60.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8252  bytes 865767 (845.4 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 92  bytes 7973 (7.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 92  bytes 7973 (7.7 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:ca:ea:1a  txqueuelen 1000  (Ethernet)
        RX packets 74  bytes 5848 (5.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 2689 (2.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether fe:54:00:f1:02:b0  txqueuelen 1000  (Ethernet)
        RX packets 7074  bytes 689499 (673.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12522  bytes 28868005 (27.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

这时候KVM内的虚拟机依然不能联网,还需要重启了一下服务(该操作不影响正在运行的KVM虚拟机使用)。

[root@localhost network-scripts]# systemctl restart libvirtd

网桥 br0 的状态也出现了一个虚拟网桥连接。

[root@localhost network-scripts]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000c29286e6d       no              ens33
                                                        vnet0
virbr0          8000.525400caea1a       yes             virbr0-nic

 

三、结果反馈

在解决网络连接问题后,又重新打开了一台虚拟机。

[root@localhost network-scripts]# virsh start centos7.0-2 
域 centos7.0-2 已开始

[root@localhost network-scripts]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 2     centos7.0                      running
 3     centos7.0-2                    running
 -     centos7_kvm                    关闭

这时候再查看网桥状态,可以发现 br0 的对端多了一个网卡 vnet1 连接 。

[root@localhost network-scripts]# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.000c29286e6d       no              ens33
                                                        vnet0
                                                        vnet1
virbr0          8000.525400caea1a       yes             virbr0-nic

由此可以总结出,KVM每创建一台虚拟机,对应的网桥就会多一个对端连接~~~

 

 

 

 

--- 20190116 ---

今天发生了一个小插曲,测试服务器,用台式电脑安装的centos7,在搭建好环境之后,各虚拟节点也都启动了,午休之后发现宿主机就连不上了。

本来以为是网桥又坏了,但是没有动过,配置完之后连接都是正常的。

然后,最后。

是电脑网线松了。

 

展开阅读全文
KVM
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部