KVM - Fix Missing Default Network
Run the steps below if you ever get this message:
ERROR Requested operation is not valid: network 'default' is not active
Steps
Stage 1
First check if you have the network defined by running:
sudo virsh net-list --all
If you got the following output then proceed to "Stage 1 - Create the Default Network". If you don't and the network exists, proceed to "Stage 2 - Start and autostart the network".
Name State Autostart Persistent
----------------------------------------------------------
Stage 1 - Create the Default Network
Create the default network by copy-pasting the following lines into a file called default.xml
.
<network>
<name>default</name>
<uuid>9a05da11-e96b-47f3-8253-a3a482e445f5</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:0a:cd:21'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
Now to add that network permanently to our KVM host, run the following:
sudo virsh net-define --file default.xml
Stage 2 - Start and autostart the network
To manually start the network run:
sudo virsh net-start default
To have the network automatically start up in future run:
sudo virsh net-autostart --network default
Debugging
Failed To Initializae Firewall Backend
Kris Maussen has kindly pointed out in the comments that if you get the following error messages:
error: Failed to start network default
error: internal error: Failed to initialize a valid firewall backend
You will need to install firewalld.
sudo apt update && sudo apt install firewalld -y
Now run the following commands in order to enable the service and make networking work again:
sudo systemctl enable --now firewalld
sudo systemctl restart libvirtd
DnsMasq Issue
If you get the following error:
error: Failed to start network default
error: Cannot check dnsmasq binary /usr/sbin/dnsmasq: No such file or directory
Just install dnsmasq.
sudo apt-get install dnsmasq -y
First published: 16th August 2018