14

How do I configure an Ubuntu 20.04 system so it overrides the default DNS?

It seems that by default there is a global and per-link DNS setting.

I tried a couple of things that did not work:

  • Edit /etc/systemd/resolved.conf with the DNS Servers
  • Created /etc/systemd/network/enp0s3.conf with the DNS servers configured
  • Removed all DNS related parameters from the DHCP request by editing /etc/dhcp/dhclient.conf

All these changes (and the combinations) result in the DNS servers being prepended to the list of global DNS servers.

Most 'solutions' are to either install resolvconf or replace the /etc/resolv.conf symbolic link with a file and set the DNS servers there. Both of these seem like a workaround.

I would like to use the existing tooling (systemd-resolved) to override the DNS Servers.

As suggested by @xenoid in the comments: Setting the DNS for the interface through the GUI resulted in a file /etc/NetworkManager/system-connections/enp0s3.nmconnection that contains the correct DNS servers, the output of resolvectl status includes the correct DNS servers, this however is not what I had in mind. I am looking for a solution that does the configuration using systemd-resolved, which is possible from what I can find, but it is unclear how. Since this requires a GUI installation.

3
  • What is your end goal here? Do you want to point the machine to your own DNS server on your local network? Are you on a home network you control or in an enterprise environment? – Martin Konrad May 24 '20 at 16:06
  • I want this system to have different DNS servers from those that are provided over DHCP. While still using the default tooling that is used for configuring DNS. – Serge Fonville May 24 '20 at 16:47
  • I want this system to have different DNS servers from those that are provided over DHCP In the network, config dialogs you can configure your system to ignore the DHCP-provided DNS and use specific ones. – xenoid May 24 '20 at 17:25
14
  1. Update /etc/systemd/resolved.conf
[Resolve]
DNS=1.1.1.1 8.8.8.8
FallbackDNS=8.8.4.4

  1. Restart system resolved: service systemd-resolved restart
  2. Run systemd-resolve --status

the output should look like this:

Global
         DNS Servers: 1.1.1.1
                      8.8.8.8
...
6
  • 2
    I did that, and that did not change the per-link DNS settings – Serge Fonville May 26 '20 at 9:06
  • @SergeFonville Is systemd-networkd active? What is the output networkctl status enp0s3 – Tombart May 27 '20 at 10:35
  • 1
    systemd-networkd is not active and networkctl status enp0s3 outputs the settings of the interface, I noticed specifically State: n/a (unmanaged). Do you want to know something specific? – Serge Fonville May 28 '20 at 22:59
  • 1
    You need to change the file the /etc/resolv.conf link points to. Point it at /run/systemd/resolve/resolv.conf. See this bug: bugs.launchpad.net/ubuntu/+source/systemd/+bug/1774632 – David R. Dec 20 '20 at 19:01
  • This did the trick for me. Thanks. – DribblzAroundU82 Apr 7 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.