Set dns once for all


I don’t want to use the dns of my internet provider.

In gnome, I can go in parameter->wi-fi, click on the parameters of the used connection, go in ipv4 and ipv6 disable the automatic mode in DNS, and set the ip of the dns I want to use.

Two problems :

  • It doesn’t work at all,
  • Even if it worked, I don’t want to have to do it each time I use a new connection.

So, I can edit /etc/resolv.conf. This works… until the next update.

(And it ask two more questions :

  • Why can I set only three dns ?
  • Why is there a parameters in the parameter windows if it has no effect ?)

So, the main question : How can I configure my dns properly, without having to do it again at each update or each time I use a new network ? Ideally using DOH or DOT.

Thank for your help.

I doubt that - but alas - as you have discovered - it is a per connection edit - so when you add another connection you have be on it again.

You don’t want to modify the DNS too freely - it is a quite important component and it is easy to create problems for yourself.

You could run a local pi-hole on your system - presumably a laptop - that could be a as solution you can enable/disable at will. Read more about this at Pi-hole - ArchWiki

Hi @Weg,

Also have a look at

…but I think @ben75’s answer is better.

@ben75: here is my systemd-resolved

#  This file is part of systemd.
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the resolved.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
# See resolved.conf(5) for details.

# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare:
# Google:
# Quad9:

If I edit only this file, nothing happen, the network manager clearly follow what is written is /etc/resorv.conf. What did I miss ?

What can I say ? I tried to put the DNS I want to use and nothing happened. When I use the same DNS in /etc/resolv.conf it work fine (until the next update). So, I deduce the system clearly use the /etc/resolv.conf address and not the one set in the parameter menu. Do you have another explanation ?

@Mirdarthos : I will first try @ben75 solution as it look cleaner.

1 Like

You need to remove openresolv and enable systemd-resolved otherwise it won’t work.

I do hope for your sake you copied the service file to /etc/systemd/system - otherwise your changes will be gone next time systemd is synced from the repo.

I uninstalled openresolved and launch sudo systemctl enable systemd-resolved, but it still doesn’t work

I haven’t done any copy. Do you means I have to copy /etc/systemd/resolved.conf in /etc/systemd/system/resolved.conf ?

I cannot see if you made the change to the file in the /usr tree or the /etc tree - that is why I mention it. All edits should be done in /etc

Did you restart your network manager ?

systemctl reload NetworkManager

For network changes to apply restarting network has to be done.

the file I showed is /etc/systemd/resolved.conf

Yes I tried to reload the network manager. No result.

You can see status of the resolver

resolvectl status

systemd can work directly with resolv.conf but the recommended setup is to symlink the systemd stub file to /etc/resolv.conf

After you have started the systemd-resolved.service a stub file will be created

Backup your resolv.conf

sudo mv /etc/resolv.conf /etc/resolv.conf.bak

Then symlink the stub file

sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
1 Like

To what must it be linked? I’m guessing /etc/resolv.conf:

sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
1 Like

Why not set it in your router configuration, if you have access to it?

I don’t want to use the dns of my internet provider.
How can I configure my dns properly, without having to do it again at each
update or each time I use a new network ? Ideally using DOH or DOT.

You need something local on the laptop like dnscrypt-proxy…

Not sure what option you did select when you disabled the “automatic” mode.

It certainly does work - when you select:
automatic (DHCP), addresses only
instead of
automatic (DHCP)

Then, the IP of the DNS server(s) you put in the box below will be the one that is used
instead of the one provided by your router
(which is the one your ISP gives you).
It is a comma separated list, as the tool tip tells which will appear when you hover the cursor over that input box.

No other changes needed - not to /etc/resolv.conf, no need to switch to systemd-resolved …

It is a per connection setting when you use the NetworkManager GUI
(you only do it once for each wlan network you connect to)

You could configure your router to use a custom DNS server instead - how that is done is specific to the router but is usually an option in the routers setup menu.
Then, all the devices that connect through that router will use the custom DNS.

1 Like