KVM虚拟机NAT模式网络无法连接

1. 问题发生

在使用virt-manager启动虚拟机后,使用一段时间后突然虚拟机网络断开,并不知道是什么原因导致。

2. 解决问题

可以看到虚拟机是使用NAT模式连接主机网络的。
KVM虚拟机NAT模式网络无法连接_第1张图片
这里使用的是virt-manager创建虚拟机时提供的default网络配置xml文件。
KVM虚拟机NAT模式网络无法连接_第2张图片
首先查看virt-manager的网卡接口,如下图中的virbr0就是KVM为虚拟机创建的网卡接口,也是作为一个switchbridge,将包分发到KVM中的各个虚拟机。
KVM虚拟机NAT模式网络无法连接_第3张图片
通过virsh重新启动default接口,提示信息显示,该接口是正常工作的。
在这里插入图片描述
通过brctl命令也可以看到virbr0网络接口也是在正常开启的。
在这里插入图片描述
到这里就很奇怪了,不知道该从和下手,在突然尝试将libvirtd服务重新启动时,看到启动时报错了。

imaginemiracle:~$ service libvitd status
● libvirtd.service - Virtualization daemon
     Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-07-01 16:28:46 CST; 3s ago
TriggeredBy: ● libvirtd-admin.socket
             ● libvirtd-ro.socket
             ● libvirtd.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
   Main PID: 41796 (libvirtd)
      Tasks: 19 (limit: 32768)
     Memory: 35.2M
     CGroup: /system.slice/libvirtd.service
             ├─19069 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
             ├─19070 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
             └─41796 /usr/sbin/libvirtd

7月 01 16:28:46 Linux-wxn systemd[1]: Starting Virtualization daemon...
7月 01 16:28:46 Linux-wxn systemd[1]: Started Virtualization daemon.
7月 01 16:28:47 Linux-wxn libvirtd[41796]: libvirt version: 6.6.0, package: 1ubuntu3.5 (Christian Ehrhardt <[email protected]> Wed, 07 Apr 2021 13:33:46 +0200)
7月 01 16:28:47 Linux-wxn libvirtd[41796]: hostname: Linux-wxn
7月 01 16:28:47 Linux-wxn libvirtd[41796]: internal error: firewalld is set to use the nftables backend, but the required firewalld 'libvirt' zone is missing. Either set the firewalld backend to 'iptables', or ensure that firewalld has a 'libvirt' zone by upgrading firewalld to a version supporting rule priorities (0.7.0+) and/or rebuilding libvirt with --with-firewalld-zone
7月 01 16:28:47 Linux-wxn dnsmasq[19069]: read /etc/hosts - 7 addresses
7月 01 16:28:47 Linux-wxn dnsmasq[19069]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
7月 01 16:28:47 Linux-wxn dnsmasq-dhcp[19069]: read /var/lib/libvirt/dnsmasq/default.hostsfile

可以看到这个错误是由于Linux的防火墙引起的,在网上找了很多解决方案却还是不能解决,于是直接将Linux的防火墙关闭,再次重启libvirtd服务错误解决,KVM中的虚拟机正常连接网络。

imaginemiracle:~$ sudo service firewalld stop
imaginemiracle:~$ sudo service libvitd restart
● libvirtd.service - Virtualization daemon
     Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-07-01 16:33:00 CST; 41min ago
TriggeredBy: ● libvirtd-admin.socket
             ● libvirtd-ro.socket
             ● libvirtd.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
   Main PID: 42261 (libvirtd)
      Tasks: 21 (limit: 32768)
     Memory: 40.8M
     CGroup: /system.slice/libvirtd.service
             ├─19069 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
             ├─19070 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
             └─42261 /usr/sbin/libvirtd

7月 01 16:33:00 Linux-wxn dnsmasq[19069]: read /etc/hosts - 7 addresses
7月 01 16:33:00 Linux-wxn dnsmasq[19069]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
7月 01 16:33:00 Linux-wxn dnsmasq-dhcp[19069]: read /var/lib/libvirt/dnsmasq/default.hostsfile
7月 01 16:33:12 Linux-wxn libvirtd[42261]: libvirt version: 6.6.0, package: 1ubuntu3.5 (Christian Ehrhardt <[email protected]> Wed, 07 Apr 2021 13:33:46 >
7月 01 16:33:12 Linux-wxn libvirtd[42261]: hostname: Linux-wxn
7月 01 16:33:22 Linux-wxn dnsmasq-dhcp[19069]: DHCPREQUEST(virbr0) 192.168.122.245 52:54:00:11:c0:55
7月 01 16:33:22 Linux-wxn dnsmasq-dhcp[19069]: DHCPACK(virbr0) 192.168.122.245 52:54:00:11:c0:55 Linux-IM
7月 01 17:03:22 Linux-wxn dnsmasq-dhcp[19069]: DHCPREQUEST(virbr0) 192.168.122.245 52:54:00:11:c0:55
7月 01 17:03:22 Linux-wxn dnsmasq-dhcp[19069]: DHCPACK(virbr0) 192.168.122.245 52:54:00:11:c0:55 Linux-IM

3. Error starting domain: Requested operation is not valid: network ‘default’ is not active

imaginemiracle:~$ virsh net-start default 
error: Failed to start network default
error: internal error: firewalld is set to use the nftables backend, but the required firewalld 'libvirt' zone is missing. Either set the firewalld backend to 'iptables', or ensure that firewalld has a 'libvirt' zone by upgrading firewalld to a version supporting rule priorities (0.7.0+) and/or rebuilding libvirt with --with-firewalld-zone
imaginemiracle:~$ sudo service firewalld stop
imaginemiracle:~$ sudo service libvirtd restart
imaginemiracle:~$ virsh net-start default 
Network default started

总结

由于防火墙的原因导致虚拟机无法通过NAT连接主机网络,关闭防火墙即可,到此算是解决了该问题吧!(由于不明发生的原因,防火墙为什么导致libvirtd服务启动default网络失败,只能算作是表面上的解决)

你可能感兴趣的:(Linux,Qemu,VMware,Linux,KVM,虚拟机)