Hi,
I'd like to give my VMs reliable addresses over DHCP and so far I was only able to do this by defining them in the libvirt's network config with 'virsh net-edit'. But as libvirt runs dnsmasq and dnsmasq usually reads /etc/hosts, it should be sufficient to just edit the hosts file.
Unfortunately this doesn't work. Why does dnsmasq ignore /etc/hosts when started from libvirt?
Regards, Christoph
On Tue, Oct 25, 2011 at 07:26:11PM +0200, Christoph Wickert wrote:
Hi,
I'd like to give my VMs reliable addresses over DHCP and so far I was only able to do this by defining them in the libvirt's network config with 'virsh net-edit'. But as libvirt runs dnsmasq and dnsmasq usually reads /etc/hosts, it should be sufficient to just edit the hosts file.
Unfortunately this doesn't work. Why does dnsmasq ignore /etc/hosts when started from libvirt?
As far as I can tell, dnsmasq should be reading /etc/hosts. Here is how libvirt starts dnsmasq:
/usr/sbin/dnsmasq --strict-order --bind-interfaces \ --pid-file=/var/run/libvirt/network/default.pid --conf-file= \ --except-interface lo --listen-address 192.168.122.1 --dhcp-range \ 192.168.122.2,192.168.122.254 \ --dhcp-leasefile=/var/lib/libvirt/dnsmasq/default.leases \ --dhcp-lease-max=253 --dhcp-no-override
Anyhow, the dnsmasq instance is private to libvirt. If you want to use features from dnsmasq, ask for them to be added to the libvirt XML (on libvir-list).
Rich.
On 10/25/2011 01:26 PM, Christoph Wickert wrote:
I'd like to give my VMs reliable addresses over DHCP and so far I was only able to do this by defining them in the libvirt's network config with 'virsh net-edit'. But as libvirt runs dnsmasq and dnsmasq usually reads /etc/hosts, it should be sufficient to just edit the hosts file.
Unfortunately this doesn't work. Why does dnsmasq ignore /etc/hosts when started from libvirt?
I just tested this locally (e.g. by doing "host mytestname" in a guest's shell) and dnsmasq doesn't ignore the entries in /etc/hosts.
One possibility why it may seem to be failing for you (but is actually working): dnsmasq reads the contents of /etc/hosts at startup; any changes made to /etc/hosts after that time will not be seen by dnsmasq until/unless you either restart dnsmasq, or send it a SIGHUP. To send a SIGHUP to all your dnsmasq processes, just do this:
killall -HUP dnsmasq
Or possibly you're misunderstanding what dnsmasq does with /etc/hosts. It will *not* (for example) search for a client's hostname during a DHCP request, and assign it the address it finds in /etc/hosts. That is what the <host> elements inside the <dhcp> element are for.
What dnsmasq *does* do with /etc/hosts: when receiving a DNS request for a hostname, it will look for a resolution for that name in /etc/hosts. libvirt doesn't disable this functionality by default, and doesn't even provide a way for the functionality to be disabled, so either you're hitting one of the two situations above, or you've encountered a bug in the version of libvirt/dnsmasq you're using.