How to Flush the DNS Cache in Linux?
Last Updated :
26 Mar, 2025
Are you facing domain resolution issues, or are the websites you're trying to browse not loading fast enough? Well, flushing the DNS cache in Linux can be a fast and effective solution. The DNS cache stores the IP addresses of all the websites you browse and over a period of time, this data becomes outdated or corrupted which causes issues while browsing the internet.
In this guide, we're going to discuss how to flush the DNS cache in Linux, using different methods so whether you're using Ubuntu, CentOS, or any other Linux distribution, this guide will help you clear DNS entries and resolve common DNS errors seamlessly.
What is DNS Cache
The DNS cache is a temporary storage that stores all the DNS records for the websites you visit on a daily basis. These records map domain names to their respective IP address and allows users to access the websites way faster. That's why this website cookies and cache become corrupted and leads to certain issues such as:
- Unable to load Website pages
- Network issues
- Slow browsing speed
- Frequent page crash
In such cases, flushing the DNS cache in Linux can help ensure that your system retrieves the latest and most accurate DNS information from the internet.
How to Find a local DNS resolver
To find that we can execute the following command to determine the local DNS resolver on our Linux system.
sudo lsof -i :53 -S
- lsof: The lsof command is used to list open files and associated processes.
- -i :53: This specifies the query for processes using port 53, which is the default port for DNS.
- -S: This option shows the processes associated with the specified socket.
Finding a Local DNS ResolverIn the output, we can see that our process is associated with port 53 which mentions "systemd-resolved". So this is our local DNS resolver.
How to Flush the DNS Cache in Linux
Below we have listed all the possible methods through which we can Flush the DNS Cache on Linux systems
Method 1: Using resolvectl Command (for systemd-based Systems)
Step 1: Open Terminal and Run the resolvectl Command
You can use Linux Keyboard Shortcut using Ctrl + Alt + T to open Terminal instantly and now we will be using the resolvectl command to flush the DNS cache on a Linux system, specifically through the flush-caches option.
sudo resolvectl flush-caches
- sudo: Executes the command with superuser privileges.
- resolvectl: The command-line client for interacting with systemd-resolved, a system service managing DNS resolution.
- flush-caches: Option instructing systemd-resolved to clear and refresh the DNS cache.
Flushing DNS Cache using resolvectl commandStep 2: Verify the DNS cache Flushing
To verify whether the DNS cache is flushed or not, we can execute the below command to verify:
sudo systemctl status systemd-resolved
- sudo: Executes the command with superuser privileges.
- systemctl: A command-line utility to control systemd services.
- status: Displays information about the current status of a service.
- systemd-resolved: The name of the service for which we want to check the status.
Verifying the DNS Cache FlushThis confirms that the DNS cache has been cleared and your system is ready to retrieve fresh DNS data.
Method 2: Using signals
The Ubuntu 20.04 and newer versions, use systemd for managing system services. If your system uses systemd-resolved to manage DNS resolution, you can flush the DNS cache using the resolvectl
command.
Step 1: Open Terminal and Run the resolvectl Command
In this method, we are sending the USR2 signal to the systemd-resolved process, prompting it to flush and refresh its DNS cache. Using signals offers an alternative method to clear the cache without restarting the entire service.
sudo killall -USR2 systemd-resolved
- sudo: Executes the command with superuser privileges.
- killall: Sends a signal to terminate or signal processes based on their names.
- -USR2: Sends the USR2 signal to the specified process, in this case, systemd-resolved.
Using signals to Flush DNS CacheStep 2: Verify the DNS cache Flushing
The below command can be used to verify the system journal logs that are related to the systemd-resolved. By using the command, we can verify the flushing process:
sudo journalctl -r -u systemd-resolved
- sudo: Executes the command with superuser privileges.
- journalctl: Retrieves and displays system journal logs.
- -r: Displays logs in reverse order (most recent first).
- -u systemd-resolved: Filters logs specifically for the systemd-resolved service.
Verifying Flushing ProcessThis command will send the USR2 signal to the systemd-resolved process, effectively clearing the DNS cache without restarting the service.
Method 3: Using systemctl
to Restart systemd-resolved (for systemd-based Systems)
You can also choose to clear the DNS cache by restarting the systemd-resolved service using systemctl and this method forces the service to reload the DNS cache. Let's see how to eprform this action:
Step 1: Open Terminal
Press Ctrl + Alt + T to access the Terminal on your Linux system instantly.
Step 2: Run the systemd-resolved Command
Run the following command and ensure that you have admin privilege:
sudo systemctl restart systemd-resolved
Step 3: Recheck by Opening the Browser
Once the service restarts, your DNS cache will be cleared. You can verify the same by opening your preferred web browser to test it by yourself.
This method is useful for those who wish to ensure that their DNS resolver service is refreshed and up-to-date.
Method 4: Using the nscd for Older Systems
This method is suitable for older Linux distributions where we can use nscd (Name Service Cache Daemon). Let's see how we can perform this action:
Step 1: Access the terminal
Press Ctrl + Alt + T to access the Terminal on your Linux system instantly.
Step 2: Run the nscd Command
Run the following command and ensure that you have admin privilege:
sudo /etc/init.d/nscd restart
Step 3: Recheck by Opening the Browser
Once the service restarts, your DNS cache will be cleared. You can verify the same by opening your preferred web browser to test it by yourself.
How to Verify if the DNS Cache Was Cleared or Not
Once you've performed any of the provided method to flush the DNS, you can verify the same by the following steps:
Step 1: Open the Terminal and Run this Command
Open the terminal and use this command to view the status of systemd-resolved:
sudo systemctl status systemd-resolved
Step 2: Test DNS resolution by using nslookup
You may also test the DNS resolution by using the nslookup command to see if the system retrieves the fresh information:
nslookup google.com
Common DNS Flushing Issues
While trying to flush the DNS cache, you might face certain issues, here's how to resolve them in no time:
1. Command Not Found: If this issue occurs while trying to run resolvectl or systemclt, ensure that your system uses systemd-resolved for DNS management. You can check the Linux distribution and its version to verify its compatibility.
2. DNS Resolution Still Fails: Try the following if the DNS resolution fails:
- Check your DNS settings in the /etc/resolv.conf file.
- Restart the Networking service using sudo systemctl restart network-manager
- Ensure that your DNS server is configured properly (for custom DNS)
3. Flush DNS Cache without systemd: You will be required to use the nscd or dnsmasq (depending upon the distribution)
Similar Reads
How to Flush DNS Cache [Windows, Mac, and Linux]
Ever tried to access a website, only to be greeted by a frustrating error message? Or maybe youâve noticed your internet slowing down for no apparent reason. These issues can often be traced back to your DNS cache, a hidden culprit that stores outdated or incorrect information about websites youâve
5 min read
How to Delete Files in Linux?
Linux comes with several tools that can assist us in removing Directories and files. We always need to delete many files and folders based on a set of requirements. To complete our mission quickly, knowing a few basic commands and their variations is beneficial. Use caution when using the commands b
6 min read
How to see cache statistics in Linux?
Cache is a very important part of the computer hardware to give superfast response time. Cache Performance When the processor needs to read or write a location in main memory, it first checks for a corresponding entry in the cache. If the processor finds that the memory location is in the cache, a c
2 min read
How to Configure DNS on Linux
Configuring DNS (Domain Name System) on Linux is a key step in managing how your system connects to the internet and resolves domain names into IP addresses. Whether youâre setting up a local server, troubleshooting network issues, or optimizing your systemâs performance, understanding DNS configura
5 min read
npm cache clean - How to Clear the Cache in NPM ?
Clearing the cache in NPM (Node Package Manager) is very important. It helps to resolve various issues and ensures smooth functioning of the Node.js projects. The NPM cache stores downloaded packages and their metadata, which can sometimes become corrupted or outdated, leading to installation proble
5 min read
fc-cache command in Linux with Examples
The fc-cache command in Linux scans the font directories and build font cache for applications which use fontconfig for their font handling. When no arguments are passed fc-cache scans each directory for font files readable by FreeType. A cache is created which contains properties of each font and t
2 min read
How to Clear the Terminal History in Linux
The Linux Terminal stores every command you execute in a history file like .bash_history for Bash or .zsh_history for Zsh, making it convenient to access previous commands. However, this history can become a privacy or security issue, especially when dealing with sensitive tasks or working on shared
6 min read
How to Clear the Cache on Facebook
Is Facebook running slower than usual or not displaying updated content? Clearing the cache on Facebook can help fix loading issues, free up storage, and improve performance. Over time, cached data, cookies, and stored files can slow down the app or cause glitches. In this guide, weâll walk you thro
9 min read
How to clear the Cache in WordPress ?
If you are new to WordPress, learning how to clear your cache is an essential skill. Clearing your cache involves removing outdated data and content from your website's temporary storage, ensuring that you and your visitors see the most up-to-date information. Why Clear Your Cache in WordPress?When
3 min read
How to Set or Change System Hostname in Linux?
A hostname is a label assigned to a device connected to a computer network. It is used to identify the device in various forms of electronic communication such as logging in, sending emails, or in network traffic. This name can be anything from a simple single-word string to a more complex string of
4 min read