Skip to content

Instantly share code, notes, and snippets.

@plembo
Last active August 29, 2022 14:48
Show Gist options
  • Save plembo/1d953f0bb7609a0520ccf2929f69b037 to your computer and use it in GitHub Desktop.
Save plembo/1d953f0bb7609a0520ccf2929f69b037 to your computer and use it in GitHub Desktop.
Reserving DHCP addresses in KVM

Reserving DHCP addresses in KVM

In using KVM (libvirtd) as part of my virtual "lab" environment at home, I often have at least a few guests using DHCP whose addresses have been reserved. Setting this up is simple, once you've read the documentation.

This configuation is done at the network level and found in the /etc/libvirt/qemu/networks/[networkname].xml file.

Here's a sample (from the doc) from the <ip> section for the configuration:

<ip address="192.168.122.1" netmask="255.255.255.0" localPtr="yes">
  <dhcp>
    <range start="192.168.122.100" end="192.168.122.254"/>
    <host mac="00:16:3e:77:e2:ed" name="foo.example.com" ip="192.168.122.10"/>
    <host mac="00:16:3e:3e:a9:1a" name="bar.example.com" ip="192.168.122.11"/>
  </dhcp>
</ip>

As you can see, all that needs to be done is to nest a <host> tag in the <dhcp> section with the mac, name and ip address to be leased.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment