Consistent IP’s and hostnames from a libvirt defined network

I’ve noticed that when saving and restoring vm’s from either virsh or virt-manager, that often the IP address of the virtual machine changes.  This can be annoying as you have to employ different methods of figuring out what the new IP of the vm actually is (login to the console, access the display, use the arp command, etc).

I figured there was a way to configure a libvirt defined network to give out the same IP address and even hostname for a given MAC address, and indeed there is.  This page documented what I needed to know: http://libvirt.org/formatnetwork.html

First, see what network you want to edit:

virsh # net-list
Name                 State      Autostart     Persistent
--------------------------------------------------
default              active     yes           yes

Then, edit the network:

virsh # net-edit default

Add a line like the following within the <dhcp> stanza:

<host mac='52:54:00:1d:aa:cb' name='f18-dev' ip='192.168.128.8' />

Save and close the file, then restart the network (if that doesn’t work, you may need to restart the libvirtd service):

virsh # net-destroy default
Network default destroyed

virsh # net-start default
Network default started

That mac address should now always get assigned the same IP and even hostname.

 

Tags: , , ,

Posted in virtualization

One Response to “Consistent IP’s and hostnames from a libvirt defined network”


Leave a Reply