Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

KVM: Configure libvirt Network

September 24, 2023 — Gregg Szumowski

You can update the network configuration for your KVM installation using the command line using the virsh command.

To list all of the available network enter the following command. The --all will is used to include the inactive networks:

# virsh net-list --all
Name State Autostart
-----------------------------------------
default active yes
NattedNetwork active yes

Then, edit the network you wish to update:

# EDITOR="vi" virsh net-edit NattedNetwork

Add host configuration(s) or whatever changes you wish to make to XML file:

<network>
<name>NattedNetwork</name>
<uuid>8483028d-667b-47e7-9a8e-f269783a8246</uuid>
<forward mode='nat'/>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:ad:b9:ed'/>
<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>

Once you’re done, restart the network for the changes to take effect:

# virsh net-destroy NattedNetwork
# virsh net-start NattedNetwork

Tags: cli, libvirt, kvm, network, motd