Configuring systemd-resolved to use custom DNS

If you’ve ever been as frustrated as I am at Ubuntu’s–technically, systemd’s–bog stubborn refusal to use the DNS servers you specify in your network configuration, this is the post for you.

I personally think it’s Bloody Stupid Johnson levels of dumb to insist on creating a local DNS resolver on every system instead of just using a nearby DNS resolver, but whatever. Ubuntu really REALLY fights you hard when you try to disable systemd-resolved, so here’s how to configure it properly instead.

This generally isn’t an issue on interfaces with purely static configurations–but on a netplan interface that uses DHCP at all, even with a staticallly configured DNS entry, systemd-resolved will ignore anything and everything but the DHCP-provided resolver when feeding its own resolver, which it will in turn force all of your applications to use.

Here’s the trick:

sudo mkdir -p /etc/systemd/resolved.conf.d
sudo nano /etc/systemd/resolved.conf.d/dns_servers.conf

Inside the new text file you’re creating, if you wanted to specify Google’s DNS you would use a stanza like so:

[Resolve]
DNS=8.8.8.8

Once you’ve created the new file with the appropriate configuration stanza, you’ll need to restart the local resolver:

sudo systemctl restart systemd-resolved

And now, FINALLY, even though your applications are forced to query the local resolver that ignores your network configs… you can at least configure that network resolver with its OWN configs that will then work.

Of course, that means that any DNS setting in /etc/netplan is a completely ignored waste of characters. Welcome to systemd.

Published by

Jim Salter

Mercenary sysadmin, open source advocate, and frotzer of the jim-jam.

Leave a Reply

Your email address will not be published. Required fields are marked *