Fix Slow Internet on Linux in 30 Seconds
In this article
If your Linux machine feels like it's crawling online, the fastest fix is often a DNS cache flush and a switch to a faster DNS server. This 30-second tweak can cut page-load times dramatically by replacing your ISP's sluggish DNS with a speedier public one. No terminal wizardry required—just a few commands that work on most distributions. You'll need sudo access (your user password) and an internet connection (even a slow one works).
What You'll Need
- A Linux computer with sudo privileges
- An active internet connection (even slow)
- Terminal app (Ctrl+Alt+T on most distros)
Step-by-Step
- Open a terminal by pressing Ctrl+Alt+T or searching for “Terminal” in your app menu.
- Check your current DNS servers with this command:
cat /etc/resolv.conf
Look for lines starting withnameserver. If you see your router's IP (like 192.168.1.1) or your ISP's DNS, that's the likely bottleneck. - Flush the DNS cache (if you use systemd-resolved, which is default on Ubuntu and many modern distros):
sudo systemd-resolve --flush-caches
If that command isn't found, trysudo resolvectl flush-cachesinstead. This clears any stale entries that might be causing delays. - Switch to a faster DNS server temporarily to test the difference:
sudo sh -c 'echo "nameserver 1.1.1.1" > /etc/resolv.conf'
This uses Cloudflare's DNS. Alternatively, use8.8.8.8(Google) or9.9.9.9(Quad9). Note that this overwrites the file, and the change may revert after reboot or network restart. - Test your speed by loading a few websites or running
ping google.comto see response times. If it's faster, you'll want to make the change permanent (see Tips). - Restart your network manager (optional) to ensure the new DNS is picked up:
sudo systemctl restart NetworkManager
On systems using systemd-networkd, usesudo systemctl restart systemd-networkd.
Common Mistakes
- Editing /etc/resolv.conf directly without backup—if you mess up, you lose DNS entirely. Always back it up first:
sudo cp /etc/resolv.conf /etc/resolv.conf.backup. - Using the wrong flush command—
systemd-resolveis deprecated in newer systemd versions;resolvectlis the modern replacement. If neither works, your system may use a different resolver (like dnsmasq), and you'll need to restart that service instead. - Assuming the DNS change is permanent—many network managers overwrite /etc/resolv.conf on reboot. If you don't configure it properly, the fix won't stick.
- Forgetting to check if the slow speed is actually DNS—if your overall bandwidth is low, DNS won't help. Run a speed test (e.g.,
speedtest-cliif installed) before and after.
Tips
- Make the DNS change permanent by editing your network manager's settings. For NetworkManager, use
nmclior the GUI: go to Settings > Network > your connection > IPv4, and set DNS to “Automatic (DHCP) addresses only” and enter1.1.1.1, 8.8.8.8in the DNS field. - Use a DNS benchmark tool like
dnspingornamebench(if available) to find the fastest DNS for your location. But for most users, 1.1.1.1 or 8.8.8.8 are solid choices. - Clear your browser's cache as well—sometimes the bottleneck is local, not network.
- If you're on a corporate or managed network, changing DNS may violate policy or break internal name resolution. Check with your admin first.
- Consider using a local DNS cache like
dnsmasqfor long-term speed improvements, but that's beyond this quick fix.
Troubleshooting
If the fix didn't work or made things worse:
- Restore your original DNS by copying the backup back:
sudo cp /etc/resolv.conf.backup /etc/resolv.conf. - Check if the DNS server is reachable:
ping 1.1.1.1. If it times out, your network might block external DNS—try a different one like 8.8.8.8. - Verify the resolv.conf file has correct permissions:
ls -l /etc/resolv.confshould show it's readable by all. If not,sudo chmod 644 /etc/resolv.conf. - Restart your router—sometimes the issue is on the router side, not your PC.
- If you're using a VPN, DNS may be handled by the VPN; check your VPN settings instead.
- As a last resort, reboot your computer. If the problem persists, the slow speed might be due to hardware, Wi-Fi signal, or ISP issues—not DNS.
Frequently Asked Questions
Will this fix work on any Linux distribution?
Yes, the commands are standard on most distributions using systemd. For older or non-systemd distros, the flush command may differ, but the DNS change via /etc/resolv.conf works universally.
Is it safe to change my DNS server?
Yes, using reputable public DNS servers like 1.1.1.1 or 8.8.8.8 is safe and often improves privacy and speed. However, avoid unknown third-party DNS servers that could be malicious.
Why did my DNS change revert after reboot?
Network managers like NetworkManager overwrite /etc/resolv.conf on startup. To make it permanent, configure DNS through your network manager's settings, not by editing the file directly.
What if I don't have sudo access?
Without sudo, you can't change system DNS or flush the cache. You could try using a browser with built-in DNS over HTTPS (like Firefox) to bypass system DNS for that browser only.
Can this fix help with slow download speeds?
Not usually. DNS only affects the time it takes to resolve domain names, not the actual data transfer speed. If downloads are slow, the issue is elsewhere (bandwidth, Wi-Fi signal, etc.).
How do I know if DNS is my problem?
If websites load slowly but downloads are fast, or if you get “server not found” errors intermittently, DNS is likely the culprit. You can also use dig google.com to see response times.