How to Fix systemd-resolved with systemd-timer

Before SystemD came out, if you wanted to set DNS servers statically, you’d just edit your network config file, set the DNS servers there, restart the networking service and everything would work as expected.

Let’s say that you tell systemd-resolved to use the following DNS servers:


If the first one fails, resolved should use

But is this what actually happens?

Not at all!

Instead of, resolved uses which you’ve never specified anywhere.

Not only does it switch to, it never bothers to switch back to if it ever comes back up.

Is this the greatest piece of software ever or what?

So how can you fix this?

Systemd Timer

Fortunately, systemd comes with a great tool for solving this problem called systemd-timer.

It’s like folks who built systemd anticipated this issue and built a tool to allow us to fix the problem by ourselves instead of forcing them to fix the buggy code. Are these the most considerate people in the world or what?

First create a file called resolved-fixer.timer at /etc/systemd/system:

Description=Trigger resolved fixer service



Then create a file called resolved-fixer.service in the same directory:

Description=Fix resolved

ExecStart=resolvectl enp3s0

Change enp3s0 to your own network interface and the DNS servers to ones you want.

Now run these commands:

systemctl daemon-reload
systemctl enable resolved-fixer.timer
systemctl start resolved-fixer.timer

From now on, systemd will automatically set the correct DNS servers every 2 minutes. There’s still a chance that resolved will set the DNS back to (did Google bribe them or something?) but this issue will be solved at the next 2 minute time lapse.


Some of your smarties will argue that you can also use a cron job for that.

Listen, you have to fully embrace systemd or else you’ll be called a hater and receive death threats via email.

That’s why you need to use a timer and not cron.