Categories: LinuxUbuntu

How to Flush the DNS Cache on Ubuntu

The DNS or the Domain Name Server can be characterized as one of the most essential parts of your link to the internet. The DNS translates the domain names to and from the IP addresses so that we don't need to remember or keep a list of all the IP addresses of the websites we ever want to access. Our systems also maintain a list of DNS records so that we can access our frequently visited websites faster through a quick resolution of IP addresses. This cache on our system needs to be flushed from time to time. This is required because websites may change their addresses time and again, so it is a good idea to avoid IP conflict by clearing the cache. Flushing the cache is also a good way to clear unnecessary data residing on our systems.

So let us see how we can flush the DNS cache on our Ubuntu Systems.

We have executed the commands and procedures mentioned in this article on an Ubuntu 22.04 LTS system. Since we are using the Linux command line-the Terminal to flush the cache, you can open it through the system Dash or the CTRL+ALT+T shortcut.

Method 1: Using systemd-resolve to flush DNS-Cache

Most Ubuntu and Debian systems are running the systemd-resolve daemon. Your system already uses it for a lot of things. So let us use it for flushing the cache through the following command:

$ sudo systemd-resolve --flush-caches

You can then check the statistics in order to make sure that your cache size is now zero, thus cleared. Run the following command in order to view the statistics:

$ sudo systemd-resolve --statistics

You cache size 0 in the above output shows that the DNS cache has been cleared.

Method 2: Using dns-clean to flush DNS-Cache

Another way to clear the DNS cache is by starting the dns-clean utility. Run the following command in your Terminal to do so:

$ sudo /etc/init.d/dns-clean start

You have now learned two effective methods to clear your DNS cache. In both the cases, the process is pretty simple and does not require you to restart your Linux system.

Vitux Staff

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago