How To Actually Change DNS Servers on Debian Bullseye

I wanted to enable OpenNIC name servers to be able to find sites on their different top level domains. So I searched for how to do it.

Oh my... Let's just say I didn't actually find what I was looking for. At all.

The two guides I found both proposed the same solution: install resolvconf and add your preferred name servers to /etc/resolvconf/resolv.conf.d/head

First of all: what? If there is already a system installed that determines the DNS servers used, then why should another system be needed?

I tried this solution to no avail, which is quite logical when you think about it. It wasn't used by any subsystems before it was installed and there was no reason that would change.

But what then? I decided to skip the internet and dig through man pages and /etc instead. I found some interesting things.


Alright! A service that handles DNS settings! The config file for it is /etc/systemd/resolved.conf and you can set DNS servers there. Then restart the service (and for some reason restart systemd-networkd too) and run "resolvectl status" to see which name servers are now used.

Fine and dandy, as the output from said command clearly showed that I was now using the OpenNIC DNS servers. Except I still couldn't find any domains on their TLDs.

Enter systemd-networkd

That was obviously a red herring, but this one should work. After a whole lot of digging I found that this takes config files where a number of different options can be specified. I wrote this:

vim /etc/systemd/network/x.network # (It has to have the .network suffix)



Every network that matches the asterisk glob pattern, which of course is every network, should now use the listed DNS servers. The systemd-networkd service was very happy with this and proceeded gleefully to not help me at all. I still couldn't reach the OpenNIC TLDs.

Back to /etc/resolv.conf

At the top of this file you'll find the following line:

# Generated by NetworkManager

This is where I should have started! I misremembered what NetworkManager is. In my mind it was just a frontend for network settings; a system that inherited configuration from the systems that did the actual work. That's not true, however. It is very much its own thing, and it does very much control a whole lot of the network stuff.

It has a config file too: /etc/NetworkManager/NetworkManager.conf

There were no comments in that file at all, but the NetworkManager.conf(5) man page was very helpful. Eventually I just added the following lines in said file:


After this I restarted NetworkManager and lo and behold, /etc/resolv.conf was rewritten and surprisingly resolvectl reported that the correct name servers were now used. I can now reach the OpenNIC TLDs.

Those Red Herrings...

I don't know what systemd-resolved or systemd-networkd do, but despite claims and expectations they don't seem to have any power over DNS settings at least.

-- CC0 Björn Wärmedal