How to flush DNS on Ubuntu and CentOS

DNS should be flushed every now and then on your Linux system to avoid IP address conflict.

DNS (Domain Name Service) is responsible for mapping a website name into the respective IP. Click here to know how to install and configure DNS on Ubuntu.

Therefore, DNS is considered being one of the critical parts of your connection to the internet. To access the frequently visited websites faster, our machines keep track of DNS records, or in other words, it caches it.

What if a website changed its address? It may cause an IP conflict. So, to avoid such a problem, your machine DNS cache should be flushed regularly. Also, clearing your DNS cache will help you removing unneeded data occupying your system and solve some technical problems related to the famous “outdated entries” error.

In this tutorial, we will show you how to flush your DNS on Ubuntu and CentOS operating systems in easy and clear steps.

Flush DNS on Ubuntu Machine

First Method: Flush DNS by using systemd-resolve

Step 1. Before flushing your DNS, you can check DNS statistics using the next command.

sudo systemd-resolve --statistics

The output should be something like that:

Cache Statistics
Cache Statistics

As per the previous screenshot, the current cache size is 6.

Step 2. Flush DNS using systemd-resolve. Since the systemd-resolve daemon is almost running on all Ubuntu systems, then we can use it to clear our DNS cache using the next command.

sudo systemd-resolve --flush-caches

Step 3. Re-run the cache statistics command.

sudo systemd-resolve --statistics

Cache Statistics After Flush

As you can see from the above screenshot, the current cache size parameter is Zero, and that is what we need.

Second Method: Flush Cache using the dns-clean command

Another method to clear our DNS cache is using the next command:

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

Third Method: Flush Cache for some Ubuntu DNS Services

Next, we will show you some commands for clearing DNS cache for some various DNS services:

  • Flush nscd service DNS Cache:
sudo /etc/init.d/nscd restart
  • Flush BIND service DNS Cache:
sudo /etc/init.d/named restart
  • Flush dnsmasq service DNS Cache:
sudo /etc/init.d/dnsmasq restart
  • If you need to flush the DNS cache for a specific domain, use the following command:
sudo rndc flushname
  • Flush DNS cache for entire LAN:
sudo rndc flush lan
  • Respectively, to flush DNS cache for entire WAN:
sudo rndc flush wan

Flush DNS on CentOS Machine

To clear your system DNS cache on a machine running CentOS platform, you can use the following command.

systemctl restart dnsmasq.service

The output should be something like that:

CentOS Flush DNS
CentOS Flush DNS

That’s all you need to know on how to flush DNS on Ubuntu and CentOS. For any further questions, leave us a comment, and we will be happy helping you.

Hend Adel
Hi! I'm Hend Adel, a freelancer technical geek with successful experience in Database, Linux and many other IT fields. I help to build solutions to suit business needs and creating streamlined processes. I love Linux and I'm here to share my skills via FOSS Linux! Thanks for reading my article.


  1. Hi there,
    I’m missing as to where the SSL certificates I am to copy to the created folder are.
    “Copy your SSL certificates to “/etc/apache2/ssl/ ” folder”


Please enter your comment!
Please enter your name here




Uninstall Programs in Ubuntu
Uninstallation of programs can be done by graphical way using the Ubuntu Software Center, and the Synaptic Package manager. Command-line way of doing it is also possible using apt-get and aptitude commands. We shall discuss each one of them in detail.
switch to linux
Do you love Windows or Linux? Being on a Linux website, it's not hard to take a guess, but what are the strong reasons to switch to Linux? Linux is a 100% free OS. Is that reason alone enough? Let's find out! Never have there been more compelling reasons to make the switch. Here are just five great reasons for users to create that magical move from the wayward world of Windows to the lauded land of Linux.