DNS, or a Domain Name System, is responsible for resolving website names into their separate IP addresses. So, if you’re having trouble connecting to a website, or if you just want a DNS change to be seen by your Ubuntu machine, you should try to flush the DNS cache. You can likewise clear DNS store in Ubuntu on the off chance that you rolled out improvements to the hosts document, and you need it to be “seen” by your framework without rebooting it. Well, if you’re in any of these situations, and you want to clear DNS cache, here is the means by which to flush DNS store in Linux:
[ad type=”banner”]Note: I’m using an Ubuntu 16.10 “Yakkety Yak” system to demonstrate these methods. However, the process should be similar on most Linux distros.
Checking if DNS Caching is Enabled:
All Linux distros don’t carry on a similar way, with regards to things like storing DNS. For instance, Ubuntu, by default, doesn’t reserve DNS. Earlier we attempt to clear DNS cache on a Linux machine, let’s check if caching is even enabled. To do this on an Ubuntu system, you can follow the steps below:
- Launch Terminal, and type “ps ax | grep dnsmasq“.
- In the output from the command, you will be able to see a field called “cache-size“. Check its value.If the value is zero, it means that caching is disabled on the system.
Note: If you want to enable DNS caching on Linux, you can do so by using the command “sudo dnsmasq -c 150”. You can use any number in place of 150, which is basically the number of entries that dnsmasq can cache.
Flush DNS Cache in Ubuntu:
If your Linux system is caching DNS entries, then you can try to flush the DNS cache in order to get rid of any DNS related problems. To clear DNS cache in Ubuntu, you can follow the steps below:
- Launch Terminal (ctrl + alt + T), and type “sudo /etc/init.d/dns-clean restart“.
- Next, type the command “sudo /etc/init.d/networking force-reload”
This will clear your DNS cache in Ubuntu, and if the problems you were experiencing were due to DNS issues, they should now be gone.
Flush DNS Cache in DNS Services on Linux:
Alike I said, Ubuntu doesn’t cache DNS entries by default, however, if you have manually installed a DNS service such as nscd, you can clear its cache. Methods to clear cache for some common DNS services are given below:
Flush nscd DNS Cache
- sudo /etc/init.d/nscd restart
Flush dnsmasq DNS Cache
- sudo /etc/init.d/dnsmasq restart
Flush BIND DNS Cache
If you’re using BIND, you can clear DNS cache by using one of the following commands:
- sudo /etc/init.d/named restart
- sudo rndc restart
- sudo rndc restart
BIND version 9.3.0, and greater, support flushing DNS cache for a particular domain, as well as for the LAN, or the WAN. You can use the following commands to make use of this feature:
- To clear DNS cache for a particular domain, use “sudo rndc flushname wikitechy.com“
- To clear DNS cache for LAN, use “sudo rndc flush lan“
- To clear DNS cache for WAN, use “sudo rndc flush wan“
[ad type=”banner”]
Bonus: Change DNS Settings in Ubuntu:
We’ve been looking at flushing the DNS reserve in Ubuntu, be that as it may, there might be situations where you simply need to roll out an improvement to the DNS settings in Ubuntu. If you want to change the DNS settings in Ubuntu, you can do that utilizing the GUI, or by means of the Terminal.
Change DNS Settings using the GUI:
Utilizing the GUI to change DNS settings is less demanding than utilizing the Terminal. However, if you use multiple connections, you should change the DNS setting for every one of them. To change DNS settings using the GUI, just follow the steps below:
- OpenSystem Settings, and click onNetwork.
2.Click on the arrow next to the name of the network you’re connected to.
- Now, click on“Settings”. This will open up the settings for that connection.
- Switch over to the IPv4 tab, and you’ll see an option called “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, just separate them with commas.
Change DNS Settings using the Terminal:
If you don’t want to use the GUI, and prefer changing DNS settings using the Terminal, you can do this by adding the nameservers to the dnsmasq config record. However, dnsmasq does not come installed by default in Ubuntu systems (dnsmasq-base, does). So, first you’ll have to install dnsmasq by launching a Terminal, and using “sudo apt-get install dnsmasq “.
- Once you have installed dnsmasq. You can edit the config file with “sudo nano /etc/dnsmasq.conf“.
- Here, you can add your DNS servers’ IP addresses where it says “Add other nameservers here“.
Clear DNS Cache in Linux Using These Methods
You can use any of these methods to clear DNS cache in a Linux system. Issues with DNS cache can cause problems such as a webpage not loading, nameserver changes not being recognized by your system, and a lot more. Once you flush DNS cache, these problems will most likely go away.