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
- Method 2: Using signals
Method 1: Using resolvectl Command
Step 1: In this method, we are 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.
Step 2: 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.
Method 2: Using signals
Step 1: 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.
Step 2: 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.
How to Flush the DNS Cache in Linux?
Flushing the Domain Name System (DNS) cache in Linux is a common troubleshooting step to resolve various networking issues and ensure the system retrieves the most up-to-date information when resolving domain names to IP addresses. The DNS cache stores previously resolved domain names and their corresponding IP addresses, reducing the time and resources required for subsequent requests. However, sometimes, outdated or incorrect information may be cached, leading to connectivity problems. Flushing the DNS cache in Linux involves clearing this stored data, prompting the system to require DNS servers for the latest information. This process can be crucial for resolving issues such as domain resolution errors, website inaccessibility, or changes in DNS configurations. This article will explore the methods to flush the DNS cache on various Linux distributions, providing users with a comprehensive guide to effectively manage and troubleshoot DNS-related issues.
Contact Us