Skip to content

Commit

Permalink
Amended documentation with a better way to setup DNS-resolving LXD co…
Browse files Browse the repository at this point in the history
…ntainers from the host machine.

Signed-off-by: Kristof Kovacs <[email protected]>
  • Loading branch information
kkovacs authored and user committed Dec 10, 2024
1 parent 76ed931 commit 878d2a5
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions doc/howto/network_bridge_resolved.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,60 @@ You must repeat the commands after each reboot and after LXD is restarted, or ma

## Make the `resolved` configuration persistent

### Solution "A"

You can automate the `systemd-resolved` DNS configuration, so that it is applied on system start and takes effect when LXD creates the network interface.

To do so, create a `systemd` network file named `/etc/systemd/network/<network_bridge>.network` with the following content:

```
[Match]
Name=<network_bridge>
[Network]
DNS=<dns_address>
Domains=~<dns_domain>
```

So for example, `/etc/systemd/network/lxdbr0.network` with the following content (your IP, of course):

```
[Match]
Name=lxdbr0
[Network]
DNS=10.167.146.1
Domains=~lxd
```

If you have NOT freshly installed `lxd` (you've rebooted since install), then you only need to reload `systemd-resolved`:

systemctl restart systemd-resolved.service

In case you **haven't rebooted yet since first initializing `lxd`**, then you need to either A) reboot the system, or B) reload `systemd-networkd` (to reload the `.network` files) and restart `lxd` (to add the routing).

networkctl reload
snap restart lxd

You can test that the configuration got applied by running:

resolvectl status

The output should contain a part similar to this (you can see the DNS server and the `.lxd` domain mentioned):

```
[...]
Link 4 (lxdbr0)
Current Scopes: DNS
Protocols: -DefaultRoute +LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 10.167.146.1
DNS Servers: 10.167.146.1
DNS Domain: ~lxd
[...]
```

This solution "A" is better than solution "B" in the sense that it is more resilient, and gets reapplied if the `lxdbr0` network is re-created for some reason (LXD update+restart occasionally does this).

### Solution "B"

You can automate the `systemd-resolved` DNS configuration, so that it is applied on system start and takes effect when LXD creates the network interface.

To do so, create a `systemd` unit file named `/etc/systemd/system/lxd-dns-<network_bridge>.service` with the following content:
Expand Down

0 comments on commit 878d2a5

Please sign in to comment.