Register dns records for the dnsmasq process

Hi !
I use lxd containers to hosts many sites, so that each lxc instance runs it’s own apache2 and all the mechanics required. This part works fine.
However, is it possible to add records to the dnsmasq process ran by lxd so that one container can solicit the apache2 process on another container directly through the bridge.
To be more specific, let’s say that I have one container that runs the site named and another container running, I would like that from the first container, any request to goes directly to the second container.
The only way I found to achieve this so far is to modify the /etc/hosts file of the first container so as to give it the ip of the second with the name of the site. This is a workaround which works fine, but unmaintainable when you have tens of containers to maintain this way.
Before asking I’ve read the docs but did not find any way to do so.
Thanks for any help/pointer provided.

You should be able to use the managed bridge network’s raw.dnsmasq setting to specify custom DNS records.

E.g. lxc network set lxdbr0 raw.dnsmasq=",n.n.n.n"

Thank you so much for your answer @tomp . I did not know about this option I could give to the bridge and for few records it works. However, I have more than 800 records, and, following your kind advice, I got to the dnsmask man page and found the --addn-hosts option that could be helpful in my specifical case. So far, I have used it this way : lxc network set lxdbr0 raw.dnsmasq="/etc/lxd-hosts" but even if it does not raise an error at startup and that the file /var/snap/lxd/common/lxd/networks/lxdbr0/dnsmasq.raw contains addn-hosts="/etc/lxd-hosts", the file doesn’t seem to be used (unless I did not understand what it does…).
I’ll keep going, because this would be a very nice feature to have working…

Try prefixing /var/lib/snapd/hostfs/ to the path you specify in raw.dnsmasq when using the snap package so the dnsmasq process can access the root filesystem of your host (rather than the internal root filesystem of the snap package).

Wow ! That was the information I needed.

Thank you so much for your kind help, this is just fine !

1 Like