阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

KVM—关闭虚拟网卡virbr0的方法

268次阅读
没有评论

共计 4250 个字符,预计需要花费 11 分钟才能阅读完成。

我们知道: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)

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计4250字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中