1. 問題發生
在使用
virt-manager
啟動虛拟機後,使用一段時間後突然虛拟機網絡斷開,并不知道是什麼原因導緻。
2. 解決問題
可以看到虛拟機是使用
NAT
模式連接配接主機網絡的。
這裡使用的是
virt-manager
建立虛拟機時提供的
default
網絡配置
xml
檔案。
首先檢視
virt-manager
的網卡接口,如下圖中的
virbr0
就是
KVM
為虛拟機建立的網卡接口,也是作為一個
switch
和
bridge
,将包分發到
KVM
中的各個虛拟機。
通過
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網絡失敗,隻能算作是表面上的解決)