How to enable DNS for your LXD containers. If your system use systemd and NetworkManager you can follow this example:

Assuming you have a network called lxdbr0 with the following configuration:

$ lxc network show lxdbr0
config:
  dns.domain: local.dev
  ipv4.address: 10.0.0.1/24
  ipv4.nat: "true"
  ipv6.address: fd42:c743:9b8:4f8e::1/64
  ipv6.nat: "true"
description: ""
name: lxdbr0
type: bridge
used_by:
- /1.0/instances/postgres-01
- /1.0/profiles/default
- /1.0/profiles/dev
managed: true
status: Created
locations:
- none

LXD will start a dnsmasq process listening on 10.0.0.1.

If systemd-resolved is not already enabled then run the following command:

$ sudo systemctl enable systemd-resolved.service

Now let’s configure NetworkManager to delegate DNS to systemd-resolved:

Then we add the DNS server for our domain local.dev on the network interface lxdbr0:

$ sudo resolvectl dns lxdbr0 10.0.0.1
$ sudo resolvectl domain lxdbr0 '~local.dev'

.. Restart NetworkManager

$ sudo systemctl restart NetworkManager

.. And try to ping one of your container :

$ ping postgres-01.local.dev
PING postgres-01.local.dev(fd42:c743:9b8:4f8e:216:3eff:fe0c:4d51 (fd42:c743:9b8:4f8e:216:3eff:fe0c:4d51)) 56 octets de données
64 octets de fd42:c743:9b8:4f8e:216:3eff:fe0c:4d51 (fd42:c743:9b8:4f8e:216:3eff:fe0c:4d51) : icmp_seq=1 ttl=64 temps=0.079 ms
64 octets de fd42:c743:9b8:4f8e:216:3eff:fe0c:4d51 (fd42:c743:9b8:4f8e:216:3eff:fe0c:4d51) : icmp_seq=2 ttl=64 temps=0.112 ms

$ ping -4 postgres-01.local.dev
PING  (10.0.0.86) 56(84) octets de données.
64 octets de 10.0.0.86 (10.0.0.86) : icmp_seq=1 ttl=64 temps=0.031 ms
64 octets de 10.0.0.86 (10.0.0.86) : icmp_seq=2 ttl=64 temps=0.101 ms
64 octets de 10.0.0.86 (10.0.0.86) : icmp_seq=3 ttl=64 temps=0.090 ms

It works for IPv6 and IPv4 :)