PublicDNS.info Live-tested public DNS
Retested every 72 hours.

How to Change DNS on Linux

Linux gives you several ways to set custom DNS servers. This guide covers systemd-resolved, NetworkManager, and direct resolv.conf editing.

Method 1 — systemd-resolved (Ubuntu 18+, Fedora, Arch)

Most modern desktop distributions use systemd-resolved to manage DNS. This is the recommended approach if your system has it.

Open the configuration file:

sudo nano /etc/systemd/resolved.conf

Find the [Resolve] section and set your DNS servers:

[Resolve]
DNS=1.1.1.1 8.8.8.8
FallbackDNS=9.9.9.9

The DNS line takes your primary servers, space-separated. FallbackDNS is used only when the primary servers are unreachable.

Save the file and restart the service:

sudo systemctl restart systemd-resolved

Verify the change took effect:

resolvectl status

Look for your DNS servers listed under the "Current DNS Server" or "DNS Servers" fields. The active link (e.g. eth0 or wlan0) should reflect your new settings.

Method 2 — NetworkManager (GUI or nmcli)

If you run a desktop environment like GNOME, KDE, or Cinnamon, NetworkManager handles your connections. You can change DNS through the graphical settings or the command line.

GUI method

Open Settings and navigate to Network (or Wi-Fi for wireless). Click the gear icon next to your active connection.

Switch to the IPv4 tab. Turn off Automatic next to DNS. Add your preferred DNS servers in the text fields — for example 1.1.1.1 and 8.8.8.8.

Click Apply. Disconnect and reconnect, or toggle the connection off and on, for the change to take effect.

Command-line method (nmcli)

First, find your connection name:

nmcli con show

Then set your DNS servers:

nmcli con mod "Connection Name" ipv4.dns "1.1.1.1 8.8.8.8"

If you want to prevent NetworkManager from using DNS servers provided by DHCP, also run:

nmcli con mod "Connection Name" ipv4.ignore-auto-dns yes

Bring the connection back up to apply:

nmcli con up "Connection Name"

Replace "Connection Name" with the actual name from nmcli con show, for example "Wired connection 1".

Method 3 — Direct /etc/resolv.conf (minimal distros, servers)

On minimal installations, containers, or servers that do not run systemd-resolved or NetworkManager, you can edit /etc/resolv.conf directly.

Open the file:

sudo nano /etc/resolv.conf

Replace or add your nameserver lines:

nameserver 1.1.1.1
nameserver 8.8.8.8

Linux reads these in order: queries go to the first nameserver, and fall back to the second if the first is unreachable. You can list up to three.

Warning: Many systems overwrite /etc/resolv.conf when a DHCP lease renews or when NetworkManager restarts. To prevent this, lock the file:

sudo chattr +i /etc/resolv.conf

This makes the file immutable. To unlock it later for editing, run sudo chattr -i /etc/resolv.conf.

How to verify your DNS servers

After making changes, confirm your system is using the correct DNS servers. Any of these commands will work:

Using dig (from the dnsutils or bind-utils package):

dig example.com

Check the ;; SERVER: line near the bottom of the output. It should show the IP address of the DNS server you configured.

Using nslookup:

nslookup example.com

The "Server" line at the top shows which resolver handled the query.

You can also inspect your active resolv.conf directly:

cat /etc/resolv.conf

If you use systemd-resolved, the file may point to 127.0.0.53 — this is the local stub resolver. Run resolvectl status instead to see the actual upstream servers.

Recommended DNS servers

Not sure which DNS servers to use? We maintain a live-tested directory of public resolvers from around the world, filtered by reliability and response time.

Browse our full directory to find the best servers for your location.

Frequently asked questions

Which method should I use?

Use systemd-resolved if your distro ships it (Ubuntu 18+, Fedora, Arch with systemd). Use NetworkManager if you have a desktop environment with a graphical network settings panel. Edit /etc/resolv.conf directly only on minimal installs or servers that do not run a DNS management daemon.

Will my DNS settings persist after a reboot?

With systemd-resolved and NetworkManager, yes. Direct edits to /etc/resolv.conf may be overwritten by dhclient or NetworkManager on the next network event unless you lock the file with chattr +i.

Can I use both IPv4 and IPv6 DNS servers on Linux?

Yes. Add IPv6 addresses alongside IPv4 in any of the three methods. For systemd-resolved, add them space-separated in the DNS= line. For resolv.conf, add a separate nameserver line for each IPv6 address.

How do I flush the DNS cache on Linux?

If you use systemd-resolved, run sudo resolvectl flush-caches. If you run dnsmasq or nscd, restart the respective service. Most minimal Linux installs do not cache DNS at all.