Why Change DNS on Linux
Linux picks a DNS server automatically through your network configuration, usually from your router via DHCP. That default server works, but it is almost never the fastest option. ISP DNS servers handle traffic for thousands of subscribers at once. During peak hours, that shared load means slower lookups, occasional timeouts, and sometimes hijacked failed lookups that redirect you to ad pages.
Switching to a dedicated public DNS provider gives you two immediate benefits. First, faster domain resolution. Every website you visit triggers multiple DNS lookups — not just the main site, but also the CDN hosting images, font services, analytics scripts, and advertising networks. A modern page loads resources from 30 to 50 different domains. If your DNS adds 40 milliseconds to each lookup, that is 1.5 to 2 seconds of pure waiting before anything renders. A faster resolver cuts that down significantly.
Second, privacy. Most ISP DNS servers log every domain you visit and keep those logs for months. Some inject tracking into failed lookups. Providers like Cloudflare, Google, and Quad9 either purge logs within 24 hours or do not log personal data at all. The tradeoff is nothing — these services are free and do not require an account.
Changing DNS on Linux is completely reversible. If the new server does not perform well, you can revert the setting using the same method within seconds. There is no risk, no cost, and no software to install.
What You Need Before Starting
Decide which DNS server you want to use first. If you are not sure, here are three solid choices that work well for most people:
- Cloudflare 1.1.1.1 — fastest global resolver, privacy-focused. Primary:
1.1.1.1, Secondary: 1.0.0.1
- Google Public DNS — reliable, massive infrastructure. Primary:
8.8.8.8, Secondary: 8.8.4.4
- Quad9 — blocks known malicious domains. Primary:
9.9.9.9, Secondary: 149.112.112.112
For the most accurate pick, run our DNS speed test first. It measures real response times from your location across 17+ public resolvers. That way you are choosing based on data, not reputation.
Also worth noting: changing DNS on a single Linux device only affects that device. Every other device on your network keeps using the old DNS. If you want to update DNS for every device at once, do it at the router level instead.
Method 1: Using NetworkManager GUI
Most desktop Linux distributions — Ubuntu, Fedora, Linux Mint, Pop!_OS, elementary OS — use NetworkManager. The easiest way to change DNS is through the desktop GUI:
- Open Settings from the system menu or application launcher.
- Navigate to Network (may be called Wi-Fi or Network & Internet depending on the distribution).
- Click the gear icon or settings button next to your active connection (Wi-Fi or Ethernet).
- Go to the IPv4 tab.
- Change the DNS setting from Automatic to Manual (or turn off Automatic DNS).
- In the DNS Servers or Additional DNS Servers field, enter your preferred DNS addresses separated by commas or spaces. For example:
1.1.1.1, 1.0.0.1
- Click Apply or Save.
- Toggle the connection off and on, or disconnect and reconnect to the network.
The exact labels vary slightly between distributions, but the flow is identical. Ubuntu uses "Additional DNS Servers" while Fedora uses a separate DNS field. Pop!_OS exposes it under the IPv4 tab alongside the IP settings. If you cannot find the field, look for a toggle that says "Automatic DNS" and turn it off to reveal the manual entry fields.
Method 2: Using nmcli (Command Line)
If you prefer the terminal or are managing a headless server, nmcli is the command-line tool for NetworkManager. It works on any distribution using NetworkManager, including Ubuntu Server, Fedora Server, and Debian.
First, find your connection name:
nmcli con show
Look for your active connection — it will be something like "Wi-Fi Name", "eth0", or "Wired connection 1". Then run:
nmcli con mod "Connection Name" ipv4.dns "1.1.1.1 1.0.0.1"
nmcli con mod "Connection Name" ipv4.ignore-auto-dns yes
nmcli con up "Connection Name"
The first command sets the DNS servers. The second tells NetworkManager to ignore DNS servers from DHCP. The third reconnects the connection to apply changes. Replace "Connection Name" with your actual connection name. Use nmcli con mod "Connection Name" ipv4.dns "" ipv4.ignore-auto-dns no to revert to automatic DNS.
For IPv6 DNS, use ipv6.dns instead of ipv4.dns. You can also set both in a single command: nmcli con mod "Connection Name" ipv4.dns "1.1.1.1 1.0.0.1" ipv6.dns "2606:4700:4700::1111 2606:4700:4700::1001"
Method 3: Using systemd-resolved
Ubuntu 18.04 and later, Fedora, Debian, Arch Linux, and most modern distributions use systemd-resolved as the DNS stub resolver. This is the most reliable method for persistent DNS changes on modern systems.
- Open the configuration file:
sudo nano /etc/systemd/resolved.conf
- Find the
[Resolve] section.
- Uncomment the
DNS= line (remove the # at the beginning) and add your servers: DNS=1.1.1.1 1.0.0.1
- Uncomment
FallbackDNS= if you want to set backup servers: FallbackDNS=8.8.8.8 8.8.4.4
- Optionally set
DNSSEC=yes to enable DNSSEC validation (requires DNSSEC-supporting resolvers).
- Save the file and restart the service:
sudo systemctl restart systemd-resolved
- Verify with:
resolvectl status
The resolvectl status command shows which DNS servers are currently active for each network interface. Look for the "Current DNS Server" line under your active interface. The output also shows which domains are being resolved through which DNS server, which is useful for debugging split-DNS setups.
If /etc/resolv.conf still shows the old DNS after making changes, it is likely managed by systemd-resolved. Run ls -la /etc/resolv.conf to check — if it is a symlink pointing to /run/systemd/resolve/stub-resolv.conf, then systemd-resolved is in control and all changes should go through resolved.conf.
Method 4: Editing resolv.conf Directly
On older distributions or systems without NetworkManager or systemd-resolved, the DNS configuration lives in /etc/resolv.conf. This method also works on lightweight distributions like Alpine Linux and on Docker containers.
- Open the file:
sudo nano /etc/resolv.conf
- Find any line starting with
nameserver and replace the IP address with your preferred DNS.
- If the file has multiple
nameserver lines, replace the first one with your primary DNS and the second with your secondary DNS.
- If no
nameserver lines exist, add them: nameserver 1.1.1.1 and nameserver 1.0.0.1
The final file should look like this:
nameserver 1.1.1.1
nameserver 1.0.0.1
Save the file and exit. The change takes effect immediately — there is no service to restart. However, many modern systems automatically overwrite /etc/resolv.conf on reboot or network reconnect. If your changes keep getting reverted, your system is likely using systemd-resolved or NetworkManager, and you should use one of the methods above instead.
Some distributions also support a /etc/resolvconf.conf file for persistent configuration. If resolvconf is installed, edit that file instead and run sudo resolvconf -u to apply changes.
Verify Your DNS Change
After changing DNS settings, verify that the new server is working correctly:
resolvectl status — Shows current DNS servers for each interface (systemd-resolved systems).
nmcli dev show | grep DNS — Shows DNS servers configured by NetworkManager.
cat /etc/resolv.conf — Shows the current name servers the system is using.
dig example.com — Performs a DNS lookup and shows which server responded at the bottom of the output (look for the SERVER line).
nslookup example.com — Simpler lookup that queries the configured DNS server directly.
You can also visit your DNS provider's verification page: Cloudflare help page shows whether you are using Cloudflare DNS, Quad9's on.quad9.net verifies Quad9 connectivity, and Google's dns.google confirms Google DNS resolution.
For a comprehensive performance check, run our DNS speed test to compare your new resolver against other providers and confirm you are getting the best possible performance.
Flush DNS Cache on Linux
After changing DNS servers, existing cached entries may still point to old IP addresses. Flushing the DNS cache ensures all lookups use the new resolver:
- systemd-resolved:
sudo resolvectl flush-caches
- nscd (Name Service Cache Daemon):
sudo systemctl restart nscd
- dnsmasq:
sudo systemctl restart dnsmasq
- BIND:
sudo rndc flush
Most modern desktop Linux distributions use systemd-resolved, so resolvectl flush-caches is the most common command. You can verify the cache was cleared with resolvectl statistics — look for "Current Cache Size" which should drop to zero after flushing.
Your browser may also maintain its own DNS cache. Chrome stores DNS entries for about one minute by default. Firefox uses the system DNS. Clearing browser cache or restarting the browser ensures fresh lookups. For a complete guide, see our DNS cache flush guide.
Recommended DNS Servers for Linux
Here are the best DNS servers for Linux users, ranked by performance and features:
| Provider |
Primary / Secondary |
Best For |
| Cloudflare |
1.1.1.1 / 1.0.0.1 |
Fastest speed, privacy |
| Google |
8.8.8.8 / 8.8.4.4 |
Reliability, global infrastructure |
| Quad9 |
9.9.9.9 / 149.112.112.112 |
Security, malware blocking |
| NextDNS |
Custom per-account |
Custom filtering, analytics |
| AdGuard DNS |
94.140.14.14 / 94.140.15.15 |
Ad blocking, tracker blocking |
For a full comparison, see our DNS providers guide and fastest DNS benchmark.
Frequently Asked Questions
How do I change DNS on Ubuntu?
Ubuntu 18.04 and later use systemd-resolved. Edit /etc/systemd/resolved.conf, set DNS=1.1.1.1 1.0.0.1 under [Resolve], then run sudo systemctl restart systemd-resolved. For desktop Ubuntu, you can also use Settings > Network > gear icon > IPv4 > Additional DNS Servers.
How do I change DNS on Fedora?
Fedora uses NetworkManager. Use the GUI: Settings > Network > gear icon > IPv4 > DNS. Or use the terminal: nmcli con mod "YourConnection" ipv4.dns "1.1.1.1 1.0.0.1" followed by nmcli con up "YourConnection".
How do I change DNS on Raspberry Pi?
Raspberry Pi OS uses systemd-resolved. Edit /etc/systemd/resolved.conf and set DNS servers, or edit /etc/dhcpcd.conf and add static domain_name_servers=1.1.1.1 1.0.0.1 for a permanent change.
Does changing DNS on Linux affect all users?
Yes, DNS settings are system-wide. When you change DNS on Linux, every user and process on that machine uses the new DNS resolver. There is no per-user DNS setting unless you configure it at the application level (like a browser with DoH enabled separately).
How do I revert DNS changes on Linux?
For NetworkManager GUI: go back to the same IPv4 settings and switch DNS back to Automatic. For nmcli: nmcli con mod "Connection" ipv4.dns "" ipv4.ignore-auto-dns no. For systemd-resolved: comment out the DNS line in /etc/systemd/resolved.conf and restart the service. For resolv.conf: delete or comment out the manual nameserver lines and restore the original servers from DHCP.