[libvirt] Making DHCP leases available to local DNS server through dnsmasq

Michal Privoznik mprivozn at redhat.com
Fri Jun 16 10:58:22 UTC 2017


On 06/16/2017 12:21 PM, jean-christophe manciot wrote:
> Yes, except that it *does not work*. As you can see below, libnss-libvirt
> is installed and configured, but the VM "KVM-Ubuntu-GNS3-Server-17.04" is
> not reachable through its DNS name.

libvirt-nss is not for translating DNS names, rather than libvirt guest
names. That is,

# virsh start myAwesomeDomain
# ssh myAwesomeDomain

> 
> # apt-cache policy libnss-libvirt
> libnss-libvirt:
>   Installed: 3.0.0-4
> ...
> # cat /etc/nsswitch.conf
> passwd:         compat
> group:          compat
> shadow:         compat
> 
> hosts: files libvirt libvirt_guest mdns4_minimal [NOTFOUND=return] resolve
> [!UNAVAIL=return] dns
> networks:       files
> 
> protocols:      db files
> services:       db files
> ethers:         db files
> rpc:            db files
> 
> netgroup:       nis
> 
> # systemctl status libvirtd
> ● libvirtd.service - Virtualization daemon
>    Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor
> preset: enabled)
>    Active: active (running) since Fri 2017-06-16 11:44:59 CEST; 11min ago
>      Docs: man:libvirtd(8)
>            http://libvirt.org
>  Main PID: 9448 (libvirtd)
>       CPU: 1.790s
>    CGroup: /system.slice/libvirtd.service
>            ├─ 5556 /usr/sbin/dnsmasq
> --conf-file=/var/lib/libvirt/dnsmasq/virtual-mgt-5.conf --leasefile-ro
> --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
>            ├─ 5557 /usr/sbin/dnsmasq
> --conf-file=/var/lib/libvirt/dnsmasq/virtual-mgt-5.conf --leasefile-ro
> --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
>  ...
>            ├─ 8805 /usr/sbin/dnsmasq
> --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro
> --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
>            ├─ 8806 /usr/sbin/dnsmasq
> --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro
> --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper
>            ├─ 9448 /usr/sbin/libvirtd
>            └─15116 qemu-system-x86_64 -enable-kvm -name
> guest=KVM-Ubuntu-GNS3-Server-17.04,debug-threads=on -S -object
> secret,id=masterKey0,format=raw,file=/var/lib/libvirt/
> 
> ...
> Jun 16 11:55:14 samsung-ubuntu dnsmasq-dhcp[8805]: DHCPREQUEST(virbr0)
> 192.168.122.124 52:54:00:03:9f:9f
> Jun 16 11:55:14 samsung-ubuntu dnsmasq-dhcp[8805]: DHCPACK(virbr0)
> 192.168.122.124 52:54:00:03:9f:9f KVM-Ubuntu-GNS3-Server-17
> # ping KVM-Ubuntu-GNS3-Server-17.04
> ping: KVM-Ubuntu-GNS3-Server-17.04: Name or service not known
> # ping KVM-Ubuntu-GNS3-Server-17.04.actionmystique.net
> ping: KVM-Ubuntu-GNS3-Server-17.04.actionmystique.net: Name or service not
> known
> # ping 192.168.122.124
> PING 192.168.122.124 (192.168.122.124) 56(84) bytes of data.
> 64 bytes from 192.168.122.124: icmp_seq=1 ttl=64 time=0.181 ms
> 64 bytes from 192.168.122.124: icmp_seq=2 ttl=64 time=0.165 ms

This suggests your DNS server might be misconfigured. Does it have a
record for the guest you're running?

> 
> A few possible explanations for that issue are:
> - something is not configured correctly
> - there is an incompatibility with NetworkManager
> - there is a bug with libnss-libvirt

That's possible. Can you see the guest in:

/var/lib/libvirt/dnsmasq/virbr0.{macs,status}

That's where the nss module gets translations from. Also, looks like
you're using 3.0.0 release. You need to restart the network after you've
set up the NSS module. The decision whether to create those files is
made when libvirt starts a network. Only in 3.3.0 release we're making
that decision more frequently and thus the restart is not needed.

virsh net-destroy virtual-mgt-5
virsh net-start virtual-mgt-5

Michal




More information about the libvir-list mailing list