How to Change Your DNS on Linux

A practical guide to changing your DNS server on Linux using the NetworkManager GUI, nmcli, or systemd-resolved, including how to enable DNS-over-TLS and verify it worked.

Updated 5 min

Linux Intermediate ~5 min
  1. Open NetworkManager connection settings

    Open your desktop's network settings (GNOME Settings > Network, or the NetworkManager applet), select your active Wi-Fi or wired connection, and click the gear icon or "Edit" to open its details.

  2. Switch IPv4 DNS to manual

    Go to the IPv4 tab, find the DNS field, and turn off "Automatic" (or "Automatic DNS"). This tells NetworkManager to use only the addresses you enter instead of your router's or ISP's DNS.

  3. Enter your DNS addresses

    In the DNS field, type 1.1.1.1,1.0.0.1 (comma-separated, no spaces) or the resolver that won your speed test. For a family-safe option, use 1.1.1.3,1.0.0.3. Click Apply or Save.

  4. Reconnect the connection

    Toggle the network off and back on (or run sudo nmcli con down "Connection Name" && sudo nmcli con up "Connection Name") so the new DNS setting takes effect immediately.

  5. Alternative: set DNS with nmcli

    From a terminal, run: nmcli con mod "Connection Name" ipv4.dns "1.1.1.1 1.0.0.1" (space-separated for nmcli), then nmcli con mod "Connection Name" ipv4.ignore-auto-dns yes, then reactivate with nmcli con up "Connection Name".

  6. Alternative: configure systemd-resolved directly

    Edit /etc/systemd/resolved.conf, set DNS=1.1.1.1 1.0.0.1 under [Resolve], optionally set DNSOverTLS=yes, then restart with sudo systemctl restart systemd-resolved.

Why change your DNS on Linux

Most Linux distributions inherit their DNS servers from DHCP — whatever your router or ISP hands out — via NetworkManager, systemd-resolved, or a plain /etc/resolv.conf. That default resolver is rarely the fastest or most private option available. Switching to a resolver like Cloudflare’s 1.1.1.1 can shave time off the lookup that happens before every new site loads, and it takes only a couple of minutes to set up and fully reverse.

Before changing anything, run the DNS speed test to see which resolver responds fastest from your actual connection, and check public DNS servers if you want to compare features like malware blocking or logging policy before you decide.

How you make the change depends on what manages networking on your system:

  • NetworkManager (most desktop distros: Ubuntu, Fedora Workstation, Debian with GNOME/KDE, Linux Mint) — use the GUI or nmcli.
  • systemd-resolved (increasingly common as the resolver backend, often paired with NetworkManager) — edit resolved.conf directly, useful on servers or minimal installs.
  • Some minimal or older distros still use a static /etc/resolv.conf with no manager at all — see the note below.

The nmcli method (CLI)

If you would rather not use a GUI, or you are on a headless server with NetworkManager installed, nmcli does the same job from the terminal. First, find your connection name:

nmcli con show

Then set the DNS servers and stop NetworkManager from adding back the DHCP-supplied ones:

sudo nmcli con mod "Connection Name" ipv4.dns "1.1.1.1 1.0.0.1"
sudo nmcli con mod "Connection Name" ipv4.ignore-auto-dns yes
sudo nmcli con up "Connection Name"

Replace "Connection Name" with the name from nmcli con show (quote it if it contains spaces). If your network also uses IPv6, set ipv6.dns the same way with 2606:4700:4700::1111 2606:4700:4700::1001.

Configuring systemd-resolved directly

On systems where systemd-resolved manages DNS (check with resolvectl status — if it lists a “Current DNS Server”, it’s active), you can set the resolver system-wide by editing its config file:

sudo nano /etc/systemd/resolved.conf

Under the [Resolve] section, set:

[Resolve]
DNS=1.1.1.1 1.0.0.1
DNSOverTLS=yes

DNSOverTLS=yes encrypts your DNS queries using DNS-over-TLS, so anyone monitoring your network traffic cannot see which domains you’re looking up (only that you’re talking to your resolver). Save the file, then restart the service:

sudo systemctl restart systemd-resolved

Note that if NetworkManager also manages this connection, it may override resolved.conf on reconnect — in that case, set the DNS through NetworkManager (GUI or nmcli) instead, since it passes its settings down to systemd-resolved automatically.

Distro differences to keep in mind

  • Ubuntu / Debian / Fedora / Linux Mint (desktop): NetworkManager is the default; use the GUI or nmcli above.
  • Arch, minimal server installs: You may be running systemd-resolved alone, systemd-networkd, or nothing at all — check resolvectl status first to see what’s actually in control.
  • Distros without a resolver manager: If neither NetworkManager nor systemd-resolved is running, DNS may come straight from /etc/resolv.conf. You can edit it directly, but any change is usually overwritten on the next reboot or DHCP renewal unless you also mark the file immutable (sudo chattr +i /etc/resolv.conf) — a blunt approach best reserved for servers with a static config.

Verify it worked

Check which resolver is actually active:

resolvectl status

Look for “Current DNS Server” and “DNS Servers” under your active interface — they should show 1.1.1.1 and 1.0.0.1 (or your chosen resolver). If resolvectl isn’t available on your distro, use dig or nslookup instead:

dig cloudflare.com

Check the SERVER line at the bottom of the output for the resolver’s address.

To clear any cached lookups from before the change, flush the resolver cache:

sudo resolvectl flush-caches

Then reload this page and run the DNS speed test again — your new resolver should show up at the top of the results.

Troubleshooting

  • resolvectl status still shows the old DNS. NetworkManager may be re-adding the DHCP DNS servers. Confirm ipv4.ignore-auto-dns is set to yes with nmcli con show "Connection Name" | grep ignore-auto-dns, then reconnect.
  • Changes to /etc/systemd/resolved.conf don’t stick. Check whether /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf (ls -l /etc/resolv.conf). If it points somewhere else, another tool — often NetworkManager — is managing DNS instead, and resolved.conf will be ignored until you fix that.
  • A site won’t load after the switch. Revert the setting (see below) and try a different resolver. A single failing site is rarely a DNS problem.
  • No noticeable speed difference. DNS only affects the lookup before a connection starts; if pages still feel slow, the bottleneck is likely your connection or the site itself, not DNS.

Revert to your old settings

  • NetworkManager GUI: Reopen the connection’s IPv4 tab and turn “Automatic” back on for DNS, then save and reconnect.
  • nmcli: Run sudo nmcli con mod "Connection Name" ipv4.ignore-auto-dns no and sudo nmcli con mod "Connection Name" ipv4.dns "", then sudo nmcli con up "Connection Name".
  • systemd-resolved: Remove or comment out the DNS= and DNSOverTLS= lines in /etc/systemd/resolved.conf, then run sudo systemctl restart systemd-resolved.

Any of these restores DHCP-assigned DNS immediately — no reboot required.