I’ve tested this in a fresh Ubuntu 20.04 VM based on steps from Networks | LXD
# Create Ubuntu 20.04 VM for testing and enter its shell.
lxc launch images:ubuntu/focal v1 --vm
lxc shell v1
# Check we are using systemd-resolved for resolution.
cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53
options edns0 trust-ad
search lxd
# Install LXD inside VM.
apt install snapd -y; snap install lxd
lxd init --auto
# Confirm lxdbr0 network settings.
lxc network show lxdbr0
config:
ipv4.address: 10.37.134.1/24
ipv4.nat: "true"
ipv6.address: fd42:1be6:9c46:ebef::1/64
ipv6.nat: "true"
description: ""
name: lxdbr0
type: bridge
used_by:
- /1.0/profiles/default
managed: true
status: Created
locations:
- none
# Launch a container connected to lxdbr0.
lxc launch images:ubuntu/focal c1
# Check DNS is working for .lxd domain inside container.
lxc exec c1 -- ping _gateway.lxd -4 -c 1
PING _gateway.lxd (10.37.134.1) 56(84) bytes of data.
64 bytes from _gateway.lxd (10.37.134.1): icmp_seq=1 ttl=64 time=0.019 ms
--- _gateway.lxd ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.019/0.019/0.019/0.000 ms
# Check DNS to lxdbr0's DNS server is working from host (manually).
apt install dnsutils -y
dig @10.37.134.1 A c1.lxd
; <<>> DiG 9.16.1-Ubuntu <<>> @10.37.134.1 A c1.lxd
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24368
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;c1.lxd. IN A
;; ANSWER SECTION:
c1.lxd. 0 IN A 10.37.134.134
;; Query time: 0 msec
;; SERVER: 10.37.134.1#53(10.37.134.1)
;; WHEN: Wed Aug 04 16:23:42 UTC 2021
;; MSG SIZE rcvd: 51
# Setup systemd-resolved in VM to query lxdbr0's DNS server for .lxd domains.
# Create /etc/systemd/system/lxd-dns-lxdbr0.service containing:
[Unit]
Description=LXD per-link DNS configuration for lxdbr0
BindsTo=sys-subsystem-net-devices-lxdbr0.device
After=sys-subsystem-net-devices-lxdbr0.device
[Service]
Type=oneshot
ExecStart=/usr/bin/resolvectl dns lxdbr0 10.37.134.1
ExecStart=/usr/bin/resolvectl domain lxdbr0 '~lxd'
[Install]
WantedBy=sys-subsystem-net-devices-lxdbr0.device
#Activate systemd server
sudo systemctl daemon-reload
sudo systemctl enable --now lxd-dns-lxdbr0
# Check resolvectl status
resolvectl status lxdbr0
Link 9 (lxdbr0)
Current Scopes: DNS
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
Current DNS Server: 10.37.134.1
DNS Servers: 10.37.134.1
DNS Domain: ~lxd
# Check DNS resolution from the host.
dig A c1.lxd
; <<>> DiG 9.16.1-Ubuntu <<>> A c1.lxd
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18783
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;c1.lxd. IN A
;; ANSWER SECTION:
c1.lxd. 0 IN A 10.37.134.134
;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Aug 04 16:39:12 UTC 2021
;; MSG SIZE rcvd: 51
ping c1.lxd -c1 -4
PING c1.lxd (10.37.134.134) 56(84) bytes of data.
64 bytes from 10.37.134.134 (10.37.134.134): icmp_seq=1 ttl=64 time=0.033 ms
--- c1.lxd ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.033/0.033/0.033/0.000 ms
So that works. Now lets try and break it…
ip link delete lxdbr0
resolvectl status lxdbr0
Failed to resolve interface "lxdbr0", ignoring: No such device
ping c1.lxd -c1 -4
ping: c1.lxd: Name or service not known
sudo systemctl reload snap.lxd.daemon
resolvectl status lxdbr0
Link 6 (lxdbr0)
Current Scopes: none
DefaultRoute setting: no
LLMNR setting: yes
MulticastDNS setting: no
DNSOverTLS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 10.37.134.1
DNS Domain: ~lxd
ping c1.lxd -c1 -4
ping: c1.lxd: Name or service not known
lxc restart c1
ping c1.lxd -c1 -4
PING c1.lxd (10.37.134.134) 56(84) bytes of data.
64 bytes from 10.37.134.134 (10.37.134.134): icmp_seq=1 ttl=64 time=0.034 ms
--- c1.lxd ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.034/0.034/0.034/0.000 ms
Seems to cope with lxdbr0 coming and going OK.