• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TinyGrab

Your Trusted Source for Tech, Finance & Brand Advice

  • Personal Finance
  • Tech & Social
  • Brands
  • Terms of Use
  • Privacy Policy
  • Get In Touch
  • About Us
Home » How to flush DNS on Linux?

How to flush DNS on Linux?

June 9, 2025 by TinyGrab Team Leave a Comment

Table of Contents

Toggle
  • How to Flush DNS on Linux: A Comprehensive Guide
    • Understanding DNS and Why Flushing Matters
    • Determining Your DNS Resolver
      • Checking if Systemd-resolved is Enabled
      • Checking for nscd (Name Service Cache Daemon)
      • Checking /etc/resolv.conf
    • Flushing the DNS Cache: Step-by-Step
      • Flushing DNS with Systemd-resolved
      • Flushing DNS with nscd
      • Flushing DNS with dnsmasq
      • Alternative: Restarting the Network Manager
    • Verifying the Flush
      • Using ping or nslookup
    • Additional Tips and Troubleshooting
    • Frequently Asked Questions (FAQs)
      • 1. What exactly is DNS caching?
      • 2. Why would I need to flush my DNS cache?
      • 3. How often should I flush my DNS cache?
      • 4. Can flushing my DNS cache cause any harm?
      • 5. What if I don’t know which DNS resolver I’m using?
      • 6. Does flushing the DNS cache affect other users on my network?
      • 7. I flushed my DNS cache, but I’m still having problems. What else can I try?
      • 8. Is there a graphical way to flush DNS on Linux?
      • 9. How does DNS flushing compare to clearing browser cache?
      • 10. Can VPN affect DNS?
      • 11. What is the Time To Live (TTL) in the context of DNS?
      • 12. Are there any security implications of flushing the DNS cache?

How to Flush DNS on Linux: A Comprehensive Guide

Flushing your Domain Name System (DNS) cache on Linux is a crucial troubleshooting step when you experience issues connecting to websites. It clears out old or incorrect DNS records stored locally, forcing your system to retrieve fresh information from DNS servers. The method for flushing the DNS cache depends on the DNS resolver your system uses. If you’re using systemd-resolved, the most common case on modern Linux distributions, you’d use the command: sudo systemd-resolve --flush-caches. If you’re using nscd, the command would be sudo systemctl restart nscd. Determining which resolver you’re using is the first key step, which we’ll cover in detail below.

Understanding DNS and Why Flushing Matters

Before diving into the ‘how,’ let’s briefly revisit why DNS is so important and why flushing the cache might be necessary. Think of DNS as the internet’s phonebook. When you type a human-readable domain name like “google.com” into your browser, DNS translates that into a machine-readable IP address (like 142.250.185.142), which is how your computer actually locates the server hosting the website.

Your system, for performance reasons, stores these DNS translations in a local cache. This cache speeds up subsequent visits to the same website. However, DNS records can change (e.g., a website migrates to a new server with a different IP address). If your local cache holds outdated information, you might experience connection errors, slow loading times, or be directed to the wrong website. That’s when flushing becomes invaluable. It forces your system to retrieve the most current DNS records, resolving these issues. It’s a simple yet powerful tool in any Linux user’s arsenal.

Determining Your DNS Resolver

The method you use to flush your DNS cache directly depends on the resolver your system is configured to use. Here’s how to figure that out:

Checking if Systemd-resolved is Enabled

Most modern Linux distributions (Ubuntu, Fedora, Debian, etc.) use systemd-resolved by default. To check if it’s active, run the following command in your terminal:

systemctl status systemd-resolved 

If the output indicates that the service is active (running), then you are likely using systemd-resolved. If the output states inactive (dead), you will need to look at other options.

Checking for nscd (Name Service Cache Daemon)

nscd is another common DNS caching daemon. To check if it’s running, use:

systemctl status nscd 

Similar to checking for systemd-resolved, look for an active (running) status. If it’s running, then the command to flush DNS cache is based on nscd.

Checking /etc/resolv.conf

The /etc/resolv.conf file contains information about the DNS servers your system is using. While it doesn’t directly tell you which resolver is caching, it provides valuable clues. If the file points to 127.0.0.53 or 127.0.0.1 as the nameserver, it strongly suggests that systemd-resolved is in use, as these are typical loopback addresses utilized by the systemd resolver.

Flushing the DNS Cache: Step-by-Step

Now that you’ve identified your DNS resolver, let’s look at the specific commands required to flush the cache.

Flushing DNS with Systemd-resolved

As mentioned earlier, this is the most common scenario. Open your terminal and execute the following command:

sudo systemd-resolve --flush-caches 

You’ll likely need to enter your password because this command requires root privileges. After running this command, you can verify that the cache has been flushed by querying a domain name using systemd-resolve:

systemd-resolve --statistics 

This command shows the DNS resolver statistics. After flushing, you can also query a specific domain and check its status with:

systemd-resolve --status example.com 

Flushing DNS with nscd

If you’re using nscd, the process is equally straightforward. Use the following command in your terminal:

sudo systemctl restart nscd 

This command restarts the nscd service, effectively flushing its DNS cache. Again, you’ll need root privileges.

Flushing DNS with dnsmasq

dnsmasq is often used as a lightweight DHCP and DNS server. If your system uses dnsmasq, the command to flush the cache is:

sudo systemctl restart dnsmasq 

Alternative: Restarting the Network Manager

In some cases, restarting the Network Manager service can also clear the DNS cache. This approach is less targeted but can be effective in certain situations. Use the following command:

sudo systemctl restart NetworkManager 

Be aware that restarting NetworkManager may briefly interrupt your network connection.

Verifying the Flush

After flushing the DNS cache, it’s a good idea to verify that it worked correctly. A simple way to do this is to try accessing a website that was previously causing problems. If the issue is resolved, then the flush was successful.

Using ping or nslookup

You can also use the ping or nslookup commands to check the IP address of a domain before and after flushing the cache. If the IP address changes after the flush, it indicates that the system is now using a different (and hopefully correct) DNS record.

For example, before flushing:

ping google.com 

Note the IP address returned. Then, flush the cache and run the ping command again. If the IP address is different, the flush was effective. The nslookup command provides more detailed DNS information:

nslookup google.com 

Additional Tips and Troubleshooting

  • Browser Cache: Don’t forget that your browser also maintains its own DNS cache. You might need to clear your browser’s cache as well for complete resolution. This is usually found in your browser’s settings under “Privacy” or “History”.
  • Check Your DNS Servers: Ensure your system is configured to use reliable DNS servers. Google’s Public DNS (8.8.8.8 and 8.8.4.4) and Cloudflare’s DNS (1.1.1.1 and 1.0.0.1) are popular and generally perform well. You can configure these in your network settings.
  • Firewall Issues: Sometimes, firewall settings can interfere with DNS resolution. Ensure that your firewall is not blocking DNS traffic (port 53).

Frequently Asked Questions (FAQs)

1. What exactly is DNS caching?

DNS caching is the process of temporarily storing DNS query results (IP addresses corresponding to domain names) on your computer or network. This speeds up future requests for the same domain, as the system can retrieve the information from the cache instead of querying DNS servers again.

2. Why would I need to flush my DNS cache?

You need to flush your DNS cache when it contains outdated or incorrect information. This can happen when a website’s IP address changes or when there are issues with your DNS server. Flushing the cache forces your system to retrieve the latest DNS records, resolving connection problems.

3. How often should I flush my DNS cache?

There’s no fixed schedule for flushing your DNS cache. You only need to do it when you suspect that outdated DNS records are causing connectivity issues. It’s a troubleshooting step, not a routine maintenance task.

4. Can flushing my DNS cache cause any harm?

No, flushing your DNS cache is a safe operation. It won’t damage your system or data. The only temporary consequence is a slight delay in accessing websites immediately after flushing, as your system needs to re-resolve the domain names.

5. What if I don’t know which DNS resolver I’m using?

If you’re unsure, start by checking if systemd-resolved is running (as it’s the default on most modern distributions). If not, check for nscd. Reviewing your /etc/resolv.conf file is also helpful, specifically if it points to loopback addresses.

6. Does flushing the DNS cache affect other users on my network?

No, flushing your DNS cache only affects your local machine. It doesn’t impact other devices on your network. Each device has its own DNS cache.

7. I flushed my DNS cache, but I’m still having problems. What else can I try?

If flushing the DNS cache doesn’t solve the issue, consider the following:

  • Restart your router: This can resolve temporary network glitches.
  • Check your internet connection: Ensure you have a stable internet connection.
  • Contact your ISP: If the problem persists, there might be an issue with your internet service provider.
  • Browser Cache: Clear your browser cache and cookies.

8. Is there a graphical way to flush DNS on Linux?

While most methods involve the command line, some desktop environments might offer graphical tools for managing network settings. These tools might indirectly affect the DNS cache, but they rarely have a dedicated “flush DNS” button. The command line methods are the most direct and reliable.

9. How does DNS flushing compare to clearing browser cache?

DNS flushing clears the DNS records stored by the operating system. Clearing browser cache removes temporary files and data stored by the browser. They are distinct processes that address different aspects of web performance and troubleshooting. It is possible that one will solve your problem while the other one will not.

10. Can VPN affect DNS?

Yes, using a VPN (Virtual Private Network) can significantly affect your DNS settings and resolution. When connected to a VPN, your DNS queries are typically routed through the VPN’s servers, masking your actual DNS requests and potentially improving security and privacy.

11. What is the Time To Live (TTL) in the context of DNS?

Time To Live (TTL) is a value that determines how long a DNS record is cached, both on your local machine and on DNS servers across the internet. Once the TTL expires, the record must be re-resolved from the authoritative DNS server.

12. Are there any security implications of flushing the DNS cache?

Flushing the DNS cache itself doesn’t directly introduce security risks. However, if your DNS has been poisoned (a DNS spoofing attack), flushing the cache will only temporarily remove the malicious records. The underlying vulnerability needs to be addressed to prevent future attacks. Using secure DNS protocols like DNS over HTTPS (DoH) or DNS over TLS (DoT) can help mitigate this risk.

Filed Under: Tech & Social

Previous Post: « How to Add an Inbox in Outlook?
Next Post: What is a Wi-Fi thermostat? »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

NICE TO MEET YOU!

Welcome to TinyGrab! We are your trusted source of information, providing frequently asked questions (FAQs), guides, and helpful tips about technology, finance, and popular US brands. Learn more.

Copyright © 2025 · Tiny Grab