Programster's Blog

Tutorials focusing on Linux, programming, and open source

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