Method 1
The easiest way to solve this is by setting an acl on /etc/hosts which forbids the dnsmasq user access to the file. On debian this user is nobody
, on ubuntu it is libvirt-dnsmasq
.
You can set an acl like this:
setfacl -m user:nobody:--- /etc/hosts
Method 2
However, if you have a very new libvirt version (not yet available on debian buster), there is now official support for this:
Libvirt v5.6.0 (2019-08-05) added support for passing custom options to dnsmasq
.
From the documentation:
A special XML namespace is available for passing options directly to the underlying dnsmasq configuration file. Usage of XML namespaces comes with no support guarantees, so use at your own risk.
This example XML will pass the option strings foo=bar
and cname=*.foo.example.com,master.example.com
directly to the underlying dnsmasq instance.
<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'>
...
<dnsmasq:options>
<dnsmasq:option value="foo=bar"/>
<dnsmasq:option value="cname=*.foo.example.com,master.example.com"/>
</dnsmasq:options>
</network>
So, I would try this:
<network xmlns:dnsmasq='http://libvirt.org/schemas/network/dnsmasq/1.0'>
...
<dnsmasq:options>
<dnsmasq:option value="no-hosts"/>
</dnsmasq:options>
</network>