How to flush the local DNS cache in linux server

May 13, 2023 / Domain and DNS

Flushing the local DNS cache in a Linux server helps resolve outdated or incorrect DNS records, ensuring that the server retrieves the most current domain name resolutions.

Follow the steps to clear the local DNS cache in the Linux Server:

Step 1: Access the Server via Terminal

Open your terminal and log in to your server.

If required, switch to the root user:

su

Enter the root password when prompted.

Step 2: Install NSCD (If Not Already Installed)

The Name Service Cache Daemon (NSCD) is required to cache and flush DNS records. It is not installed by default on all Linux distributions.

On RedHat-based systems (CentOS, Fedora, RHEL):

sudo yum install nscd

On Debian-based systems (Ubuntu, Debian):

sudo apt-get install nscd

Once installed, ensure the service is enabled:

sudo systemctl enable nscd

Step 3: Restart the NSCD Service to Flush DNS Cache

On modern Linux systems that use systemd, restart the NSCD service using the following command:

sudo systemctl restart nscd

Restarting the service clears the local DNS cache and forces the server to fetch updated DNS records.

Flushing the DNS cache using NSCD is an effective way to resolve DNS-related issues on a Linux server. Ensure NSCD is installed and managed using systemctl, as older init-based commands are no longer supported on modern Linux distributions.

Need to flush the DNS cache on Windows 11? Read our guide on How to Flush the DNS Cache on Windows 11 using run command

Spread the love