Changing DNS with systemd-resolved

The file /etc/resolv.conf contains the following lines:

# This file is managed by man:systemd-resolved(8). Do not edit.

So when we want to change the DNS settings we are going to change the file /etc/systemd/resolved.conf

#  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.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
# See resolved.conf(5) for details


After that is done and you saved the file, you run from the command line:

service systemd-resolved restart

Now you can see the status of your changes

systemd-resolve --status

Now you should see:

       LLMNR setting: no
MulticastDNS setting: no
  DNSOverTLS setting: no
      DNSSEC setting: no
    DNSSEC supported: no
  Current DNS Server:
         DNS Servers:
Fallback DNS Servers:
          DNS Domain: enovision.local
          DNSSEC NTA:
                      ... etc ...           

The changes are not persistent !!!

Better alternative

sudo systemd-resolve --interface wlp2s0 --set-dns --set-domain yourdomain.local

where wlp2s0 is the name of your (wireless) network card. You can easily check this with ifconfig

To make these settings current, deactivate your network card once before reactivating it again

Last update: Tue, 13 Sep 2022 14:32:15