Hostname IP resolution for KVM guests: Difference between revisions

From regional-training
(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...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
==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>
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>


Line 14: Line 14:
   virst list
   virst list


Now you can confirm what guest VM hosts are running and use those hostnames to confirm that the DNS lookup is complete:
Now you can confirm what guest VM hosts are running and use those hostnames to confirm that the host name lookup resloves to the guest's NIC IP address.
 
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 automatic now.
* ping each host in the list
<pre>
fping debian10-work debian11 debian96-cloud debian11-transfer
 
debian11-transfer is alive
debian10-work is alive
debian11 is alive
debian96-cloud is alive
</pre>
 
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.


[[category:Public]]
[[category:Public]]
[[category:VM]]
[[category:VM]]
[[category:DNS]]
[[category:DNS]]

Latest revision as of 11:21, 9 June 2023

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 host name lookup resloves to the guest's NIC IP address. 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 automatic now.