Tag Archives: virsh

Reconfiguring KVM-based networking DHCP range with virsh

Whilst building a KVM-based virtualisation server on CentOS 6.4, I noticed that the default network created during the installation of the KVM/QEMU packages (192.168.122.0/24) allocated the entire address space to DHCP, as can be seen below in virt-manager (click to enlarge):

virtualnetwork

All of the configuration fields are read-only, and I wanted to reduce the DHCP scope so that I could build statically-addressed virtual servers without the hassle of creating static DHCP reservations for them. This scope can also be confirmed by looking at the current running dnsmasq configuration (dnsmasq is used by KVM/QEMU to manage DHCP):

The powerful virsh shell can be used to perform this modification and directly alter the XML configuration that backs the virtualisation platform.

To start, run virtsh net-edit <network-name> to fire up your $EDITOR:

Prior to making any modifications, my configuration was as follows:

Next, reduce the DHCP range as required - my modified configuration is as follows:

Once you quit your editor, you’ll see a message as follows, indicating that the change has been made:

If at this stage you dump the configuration with virsh net-dumpxml <network-name> you will see that the changes have NOT yet been applied:

To apply the changes, restart the network with virsh net-destroy <network-name> and virsh net-start <network-name>:

Now, a dump of the XML shows that the changes have been applied

as does another ps on the dnsmasq process:

Now, launching virt-manager shows that the desired DHCP scope is in effect:

virtnetwork-updated

Another case of command line winning over the GUI. virsh is a VERY powerful command, and there will be more articles on its usage as I dabble more with KVM-based virtualisation.