我們知道:kvm虛擬化環境安裝好後,ifconfig會發現多了一個虛擬網路卡virbr0
這是由於安裝和啟用了libvirt服務後生成的,libvirt在伺服器(host)上生成一個 virtual network switch (virbr0),host上所有的虛擬機器(guests)通過這個 virbr0 連起來。預設情況下 virbr0 使用的是 NAT 模式(採用 IP Masquerade),所以這種情況下 guest 通過 host 才能訪問外部。
但是大多數情況下:
我們虛擬機器使用的是bridge(網橋)直接連到區域網裡,所以這個 virbr0 不是必須的(注:不要搞混淆了,bridge 和這裡的 virbr0 bridge 是互不相干的)。
那麼如何關掉這個 virbr0 呢?
下面對關閉這個virbr0虛擬網路卡的操作做一記錄:
總結為以下三步:
1)首先net-destroy
2)接著net-undefine
3)最後重啟libvirtd讓設定生效
[root@kvmserver ~]# ifconfig
br0 Link encap:Ethernet HWaddr C8:1F:66:F4:FC:4F
inet addr:192.168.1.8 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ca1f:66ff:fef4:fc4f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:135245 errors:0 dropped:0 overruns:0 frame:0
TX packets:101444 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13942261 (13.2 MiB) TX bytes:7634359 (7.2 MiB)
em1 Link encap:Ethernet HWaddr C8:1F:66:F4:FC:4E
inet addr:103.10.86.8 Bcast:103.10.86.63 Mask:255.255.255.192
inet6 addr: fe80::ca1f:66ff:fef4:fc4e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1565647 errors:0 dropped:0 overruns:0 frame:0
TX packets:433759 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:371869769 (354.6 MiB) TX bytes:332186615 (316.7 MiB)
Interrupt:35
em2 Link encap:Ethernet HWaddr C8:1F:66:F4:FC:4F
inet6 addr: fe80::ca1f:66ff:fef4:fc4f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1306151 errors:0 dropped:0 overruns:0 frame:0
TX packets:95447 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:163400847 (155.8 MiB) TX bytes:7174405 (6.8 MiB)
Interrupt:38
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:128908 errors:0 dropped:0 overruns:0 frame:0
TX packets:128908 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:25188477 (24.0 MiB) TX bytes:25188477 (24.0 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:E7:2D:22
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@kvmserver ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.c81f66f4fc4f no em2
virbr0 8000.525400e72d22 yes virbr0-nic
[root@kvmserver ~]# virsh net-list
Name State Autostart Persistent
--------------------------------------------------
br0 active yes yes
default active yes yes
[root@kvmserver ~]# virsh net-destroy default
Network default destroyed
[root@kvmserver ~]# virsh net-undefine default
Network default has been undefined
[root@kvmserver ~]# service libvirtd restart
Stopping libvirtd daemon: [ OK ]
Starting libvirtd daemon: [ OK ]
[root@kvmserver ~]# virsh net-list
Name State Autostart Persistent
--------------------------------------------------
br0 active yes yes
[root@kvmserver ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.c81f66f4fc4f no em2
再次ifconfig檢視,發現virtbr0網路卡已經消失了!
[root@kvmserver ~]# ifconfig
br0 Link encap:Ethernet HWaddr C8:1F:66:F4:FC:4F
inet addr:192.168.1.8 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ca1f:66ff:fef4:fc4f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:161858 errors:0 dropped:0 overruns:0 frame:0
TX packets:123581 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:15735341 (15.0 MiB) TX bytes:9481865 (9.0 MiB)
em1 Link encap:Ethernet HWaddr C8:1F:66:F4:FC:4E
inet addr:103.10.86.8 Bcast:103.10.86.63 Mask:255.255.255.192
inet6 addr: fe80::ca1f:66ff:fef4:fc4e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1850577 errors:0 dropped:0 overruns:0 frame:0
TX packets:696879 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:407720396 (388.8 MiB) TX bytes:592419489 (564.9 MiB)
Interrupt:35
em2 Link encap:Ethernet HWaddr C8:1F:66:F4:FC:4F
inet6 addr: fe80::ca1f:66ff:fef4:fc4f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1572393 errors:0 dropped:0 overruns:0 frame:0
TX packets:115724 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:196738740 (187.6 MiB) TX bytes:8750347 (8.3 MiB)
Interrupt:38
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:350174 errors:0 dropped:0 overruns:0 frame:0
TX packets:350174 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:68170777 (65.0 MiB) TX bytes:68170777 (65.0 MiB)