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,在搭建好環境以後,各虛擬節點也都啓動了,午休以後發現宿主機就連不上了。

原本覺得是網橋又壞了,可是沒有動過,配置完以後鏈接都是正常的。

而後,最後。

是電腦網線鬆了。

相關文章
相關標籤/搜索