KVM网桥

安装KVM的虚拟机从新启动后,网桥就出现了问题,内部建立的虚拟机采用NAT能够联网,可是bridge的形式就失败了。centos

1、问题描述

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

 

2、排查步骤

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 网桥以前,咱们先中止该网卡,而后删除该网卡对应的网桥。oop

[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。centos7

[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 一致。spa

[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虚拟机使用)。rest

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

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

[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

 

3、结果反馈

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

[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,在搭建好环境以后,各虚拟节点也都启动了,午休以后发现宿主机就连不上了。

原本觉得是网桥又坏了,可是没有动过,配置完以后链接都是正常的。

而后,最后。

是电脑网线松了。

相关文章
相关标签/搜索