DNS or Domain Name System is responsible for resolving website names to their respective IP addresses. There are multiple DNS servers and you can pick and choose the one you want to use. So, if you are having trouble connecting to a website or just want a DNS change to be seen by your Ubuntu machine, you should try clearing the DNS cache. You can also clear the DNS cache in Ubuntu if you have made changes to the hosts file and want it to be “seen” by your system without rebooting. If you are in any of these situations and want to clear the DNS cache, here is how to clear the DNS cache in Linux.
note: I am using an Ubuntu 16.10 “Yakkety Yak” system to demonstrate these methods. However, the process should be similar on most Linux distributions.
Clear DNS Cache on Linux in 2020
Before we move on to our tutorial, let’s see if DNS caching is enabled on your machine.
Checking if DNS Caching is Enabled
Not all Linux distributions behave the same when it comes to things like DNS caching. For example, Ubuntu does not cache DNS by default. Before we try to clear the DNS cache on a Linux machine, let’s check if caching is enabled. To do this on an Ubuntu system, you can follow the steps below:
1. Start terminal and type “ps ax | grep dnsmasq“.
2. In the output of the command, you will be able to see a field named “.cache size“. Check the value. If the value is zero, caching is disabled on the system.

note: If you want to enable DNS caching on Linux, you can do so using the command “sudo dnsmasq -c 150”. You can use any number instead of 150 which is basically the number of entries dnsmasq can cache.
Clear DNS Cache in Ubuntu
If your Linux system caches DNS entries, you can try clearing the DNS cache to get rid of DNS related issues. You can follow the steps below to clear DNS cache in Ubuntu:
1. Launch terminal (ctrl + alt + T) and type “in”sudo /etc/init.d/dns-clean reboot“.

2. Next, type the command “sudo /etc/init.d/networking force-reload”

This will clear your DNS cache in Ubuntu and if the issues you’re experiencing are due to DNS issues, they should now be gone.
Flush DNS Cache in DNS Services on Linux
As I said, Ubuntu does not cache DNS entries by default, but if you have manually installed a DNS service like nscd, you can clear its cache. Here are the methods to clear the cache for some common DNS services:
nscd Clear DNS Cache
- sudo /etc/init.d/nscd reboot

dnsmasq Clear DNS Cache
- sudo /etc/init.d/dnsmasq reboot

Clear BIND DNS Cache
If you are using BIND, you can clear the DNS cache using one of the following commands:
- sudo /etc/init.d/named reboot
- sudo rndc reboot

- sudo rndc execution

BIND version 9.3.0 and above supports DNS cache flushing for a specific domain as well as for LAN or WAN. You can use the following commands to use this feature:
- To clear the DNS cache for a specific domain “sudo rndc wash name beebom.com“

- To clear the DNS cache for LAN “sudo rndc flush lan“
- To clear the DNS cache for WAN “sudo rndc flush wan“

Bonus: Change DNS Settings in Ubuntu
We were talking about clearing the DNS cache in Ubuntu, but there may be cases where you want to make changes to the DNS settings in Ubuntu. If you want to change DNS settings in Ubuntu, you can do so using the GUI or via Terminal.
Change DNS Settings using GUI
Using the GUI to change DNS settings is easier than using Terminal. However, if you are using multiple connections, you will need to change the DNS setting for each. To change DNS settings using the GUI, simply follow these steps:
1. Open System settingsand click on Network.
2. Click on arrow next to network name you are connected.

3. Now, click on “Settings”. This will open the settings for that connection.

4. Switch to the IPv4 taband you will see an option named “.Additional DNS Servers“. You can enter the DNS servers you want to use in this field. If you want to enter more than one DNS server, simply separate them with commas.

Change DNS Settings using terminal
If you don’t want to use the GUI and prefer to change DNS settings using Terminal, you can do this by adding the nameservers to the dnsmasq configuration file. However, dnsmasq is not installed by default on Ubuntu systems (dnsmasq-base does). So, first you will need to install dnsmasq by starting a Terminal and using “sudo apt-get install dnsmasq“.

- after installing dnsmasq. You can edit the configuration file with “.sudo nano /etc/dnsmasq.conf“.

- Here you can add the IP addresses of your DNS servers where it says “.Add other nameservers here“.
SEE ALSO: How to Boot Live Linux USB on Mac (Guide)
Clear DNS Cache in Linux Using These Methods
You can use any of these methods to clear the DNS cache on a Linux system. Problems with the DNS cache can cause problems such as a web page not loading, name server changes not being recognized by your system, and much more. These problems will most likely go away once you clear the DNS cache. So, have you ever had to clear the DNS cache on your Linux system? If so, which method did you use? If you know of any other method to clear the DNS cache on your Linux system, let us know in the comments section below.
Support our work ❤️
If you enjoyed this article, consider leaving a tip to help us keep publishing great content.





























