Disable DHCP on a QEMU/libvirt/KVM Network

Tags: devops virtualization

Libvirt + QEMU + KVM allows easy virtualization on Linux. Virtual machines are placed on a virtual network that comes complete with a DHCP server and DNS forwarder. There’s no reason to give up these default conveniences until your work involves building and configuring DNS and DHCP servers. Running two DHCP servers on the same virtual network is a recipe for frustration.

The configuration files for libvirt are stored in /etc/libvirt by default, but pretend like they aren’t even there. Read any of the files and you’ll find a warning:

<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
virsh net-edit devservers
or other application using the libvirt API.
-->

XML

They aren’t kidding. Don’t change these files. There’s one other trick:
Running the net-edit command alone won’t really do anything either if the network is already running. The following operations will do the trick:

root@host # virsh
virsh # net-destroy yournetwork
virsh # net-edit yournetwork
[remove the <dhcp></dhcp> element, save, exit]
virsh # net-start yournetwork

Bash

Rumor has it that later versions of the virt-manager GUI support these operations, but this info will come in handy if you’re still on a LTS system.

Reconnect any hosts that were on the virtual network, because they aren’t anymore. Configure your own DHCP server or configure all hosts with static interfaces as well. Remember that you’re on your own for DNS resolution in addition to DHCP at this point. An easy solution is to set domain-name-servers in your dhcpd.conf file to your router or access point.

Now that we’ve wrapped up our business here, I’d like to take a minute to tell you how happy all this stuff makes me. I’m running a small colony of machines on my middle of the line desktop computer, and I can practice the exact same work that happens in real data centers. Back when I was a newbie every machine was a real, physical machine, and PXE booting required careful hardware selection.

We’re living in the future. We just need the Hoverboard design team to catch up.

San Diego Comic-Con 2011 - Marty's Back to the Future II hoverboard (Profiles in History booth)