Hostname IP resolution for KVM guests

From regional-training
Revision as of 11:17, 9 June 2023 by Ralph (talk | contribs) (Created page with "==Guest IP via DNS lookup== The libvirt manages the DHCP of each KVM guest. Wouldn't it be nice if the DHCP IP address mappings were correlated with the host DNS lookup so IP addresses of the guests were available via VM host name?<ref>Say hello to Libvirt NSS module https://www.cyberciti.biz/faq/find-ip-address-of-linux-kvm-guest-virtual-machine#https://www.cyberciti.biz/faq/find-ip-address-of-linux-kvm-guest-virtual-machine/</ref> This is how to setup you KVM host so...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Guest IP via DNS lookup

The libvirt manages the DHCP of each KVM guest. Wouldn't it be nice if the DHCP IP address mappings were correlated with the host DNS lookup so IP addresses of the guests were available via VM host name?[1]


This is how to setup you KVM host so VM guest IP addresses are available by DNS host lookup:

  • install libnss-libvirt
apt install libnss-libvirt
  • configure /etc/nsswitch.conf to search libvirt and libvirt_guest for DNS records.
hosts: files libvirt libvirt_guest mdns4_minimal dns myhostname mymachines  [NOTFOUND=return]

🚩 Note:Make sure you name your VM guests hostname the same as their virsh domain-name.

  • Obtain the list of active KVM domain (hosts if you follow the above note):
 virst list

Now you can confirm what guest VM hosts are running and use those hostnames to confirm that the DNS lookup is complete:

  • ping each host in the list
fping debian10-work debian11 debian96-cloud debian11-transfer

debian11-transfer is alive
debian10-work is alive
debian11 is alive
debian96-cloud is alive

it has been so painful up to this date (2023-05-30) maintaining guest host names in /etc/hostname; I am glad that is all over now.