This question still doesn't have an accepted answer and as I've also had tremendous problems resolving container names on the host, I thought I should provide my solution. I am also doing this, as this page is the first google result, when looking up persistent changes to sytemd-resolved.service. Lastly I want to mention that this problem seems to be specific to Ubuntu >= 18.04
and it's version of systemd-resolved.service
.
So, the manpage systemd-resolved.service has been mentioned already. In case of LXD, misleading conclusions have been drawn out of it however. The LXD interface doesn't need to be defined in /etc/systemd/network/<iface>.{conf|network}
. The interface is already working and therefore doesn't need to be defined for systemd's network manager. By default LXD already has a working DNS server listening on it's networks first host address. All we need to accomplish is getting systemd-resolved.service
to recognize this server.
The manpage (linked above) mentions this for /etc/systemd/resolved.conf
:
The default configuration is defined during compilation, so a configuration file is only needed when it is necessary to deviate from those defaults. By default, the configuration file in /etc/systemd/ contains commented out entries showing the defaults as a guide to the administrator. This file can be edited to create local overrides.
I want to highlight This file can be edited to create local overrides.
@quat in fact you also refer to this in your actual question:
In order to make the above persistent, I have reviewed the systemd-resolve manpage http://manpages.ubuntu.com/manpages/bionic/man8/systemd-resolved.service.8.html. It suggests to create a /etc/systemd/resolved.conf.d/lxd.conf
file but there are no parameters available that would allow me to make such configuration specific to one particular NIC.
1. Adding lxd's dnsmasq service to systemd-resolved.service global dns settings:
I am not understanding your last sentence however. You don't need to specify the NIC. You merely need to specify the LXD dns server address. Using your network information a working config for /etc/systemd/resolved.conf
would look like this (uncomment to change defaults):
[Resolve]
DNS=10.78.38.1
#OBFallbackDNS=
Domains=LXD
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
After saving the file either restart your server or just systemctl restart systemd-resolved.service
For me this worked just fine on a fresh Ubuntu-18.04.02 installation. If it doesn't work for you, I presume you either did a non-default lxd install or you are having problems/conflicts due to your os upgrade.
2. UPDATE (NIC specific setup):
According to Simos' Blog the only way to persist
$ sudo systemd-resolve --interface lxdbr0 --set-dns 10.78.38.1 --set-domain lxd
is creating a custom systemd service initializing the NIC specific configuration at system start. This way is currently the "accepted" approach on "semi-official" linuxcontainers.org
Example mentioned on the blog:
Shell script enabling nic specific dns via systemd-resolve (lxdhostdns_start.sh)
$ cat /usr/local/bin/lxdhostdns_start.sh
#!/bin/sh
LXDINTERFACE=lxdbr0
LXDDOMAIN=lxd
LXDDNSIP=`ip addr show lxdbr0 | grep -Po 'inet \K[\d.]+'`
/usr/bin/systemd-resolve --interface ${LXDINTERFACE} \
--set-dns ${LXDDNSIP} \
--set-domain ${LXDDOMAIN}
Shell script disabling nic specific dns via systemd-resolve (lxdhostdns_stop.sh)
$ cat /usr/local/bin/lxdhostdns_stop.sh
#!/bin/sh
LXDINTERFACE=lxdbr0
/usr/bin/systemd-resolve --interface ${LXDINTERFACE} --revert
Creating a systemd service to manage the two scripts and haven them initialized at system startup:
$ sudo cat /lib/systemd/system/lxd-host-dns.service
[Unit]
Description=LXD host DNS service
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/local/bin/lxdhostdns_start.sh
RemainAfterExit=true
ExecStop=/usr/local/bin/lxdhostdns_stop.sh
StandardOutput=journal
[Install]
WantedBy=multi-user.target
Last but not least run systemctl enable lxd-host-dns.service
and reboot host to verify the changes being persistent by running systemd-resolve --status
. The lxbr0
interface should now be in dns scope (Current Scopes: DNS
). Considering your network it should look like this:
Link 3 (lxdbr0)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 10.78.38.1
DNS Domain: lxd
I am well aware of it not being the ideal solution and technically it still doesn't give an answer to your question about persisting this config within systemd-resolve. The problem with persisting it however, lays in the fact that the lxbr0 interface isn't managed by netplan but by systemd on Ubuntu18.04. As netplan doesn't know about the interface, you cannot use the aformentioned *.network
interface configurations to add dns and domain settings to lxbr0
.
This answer is a long long wall of text now but I hope it at least clarifies the problem a little bit. Both solutions resolve container names on an ubuntu host. The second one is more accurate, but if the only requirement is name resolution on the host, making lxd's dnsmasq service globally available via /etc/systemd/resolved.conf
is a viable alternative, especially as it only requires two edits in a config file.
Name
option inside[Match]
section.