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. In order 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 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 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





best video players for linux
Most Linux-based systems come with a built-in video player, but let's be honest, it most definitely won't be able to satisfy all of your requirements, due to the fact that default software is mostly made for basic purposes. In this article, we will review the 5 Best Video Players for Linux and thoroughly discuss their features as well as their pros and cons.
terminate frozen app
For dealing with a frozen app or desktop, you can't use the CTRL+ALT+DEL in Linux system. Instead, there are powerful alternatives that come in handy in frustrating situations. We pick the best methods available for you.
screen capture apps linux
Do you want to make a video tutorial for YouTube or show-off your epic victory royale to your friends? Look no further — as we have compiled the 10 Best Screen Capturing Software for Linux. Whether you need to record your desktop screen or take a simple screenshot, FOSSLinux has got your back.