For people who are running the Linux operating system on their devices and having a connection issue, the most effective way to fix this it to flush DNS on Linux.
DNS is also referred to as Domain Name System, and it is used by the system to resolve website names according to their IP addresses. You can easily find multiple DNS servers and pick the one you want to utilize. If you just want to change a DNS to make it visible to your Ubuntu device, or having problem in your network connection, such as it doesn’t load websites properly or can’t connect to them, Flushing DNS on Linux might solve this problem.
Moreover, you can also flush DNS cache in Ubuntu if you have modified the host file, and now want to make it visible to your system without restarting it. Flushing DNS cache on Linux is a simple process, and below you will find how you can do that.
Why Should you Flush DNS Cache on Linux?
Just like web browsers that store the cache file for instant uploads, the same thing happens with operating systems to store cache files, which are known as DNS. All of these files contain all the data about visited websites, including IP addresses, hostnames, and resource records.
These DNS cache files’ validity time is determined by TTL (Time To Live), which means as long as these DNS cache files are valid, they will work flawlessly. But as soon as these DNS files get corrupted or expired, users start encountering problems when accessing some websites.
There are multiple reasons that require you to flush DNS cache files to solve the issues. Below are some of them;
- Storing DNS records will make you an easy target of hackers that can easily steal your browser history.
- DNS cache files are also the primary reason for DNS spoofing, which can lead users to lose their critical data, such as login passwords and other sensitive information.
- Flushing DNS cache files will help you to search for up to date DNS records that will also help users to solve problems, like loading the web pages properly.
Checking DNS Cache
Before we proceed further to flush Linux DNS cache, it is required to check whether it is enabled on your device or not. Checking DNS cache status on Linux is a pretty simpler process. If you want to check DNS cache on your Ubuntu machine, here is how to do that;
Step One: Launch the Terminal from your device.
Step Two: Type the command ps ax | grep dnsmasq and press Enter.
Step Three: The output that you will get from the above-mentioned command, it will let you see the field CACHE-SIZE. Now, if the value of that field is equal to zero, you don’t need to flush the DNS on Linux since it is already disabled.
Note: For users who want to enable DNS cache on Linux operating system, you just need to use sudo dnsmasq –c 100. Moreover, you can replace the number 100 with any value up to 150. It only represents the entries of dnsmasq.
How to Flush DNS Cached on Linux?
Linux operating system doesn’t store DNS cache files by default. But some users install DNS services like NSCD (Name Service Caching Daemon). Here is how you can flush the DNS of Linux.
Step One: Open the terminal window from your Linux operating system device by pressing CTRL+ALT+T at a time.
Step Two: In the command box, you have to type the following command, which will flush all the DNS cache of your Linux device.
- Sudo /etc/init.d/nscd restart
Flushing dnsmasq DNS Cache
To flush the dnsmasq DNS cache, you just need to type the following command in Terminal;
- Sudo /etc/init.d/dnsmasq restart
Flushing BIND DNS Cache
For users who are using BIND, they just need to type the following command to clear DNS cache;
- Sudo /etc/init.d/named restart.
- Sudo rndc restart.
- Sudo rndc exec.
For users who are running BIND 9.3 or the latest version, they support DNS cache flush for a single domain, WAN, and LAN as well. Below are some more useful commands for you;
- If you want to clear DNS cache file of a specific domain, you can use the command;
- Sudo rndc flushname “domain name” without quotes.
- If you want to clear DNS cache for LAN network, you can use the command;
- Sudo rndc flush LAN
- If you want to clear DNS cache files for Wireless network, you can sue the command;
- Sudo rndc flush WAN
Flushing DNS Cache Files on Ubuntu
If you are running a Linux operating system, and it is caching DNS, you should try to flush DNS cache to prevent the DNS problems you are confronting with. Here are the commands that you will be required to flush DNS cache files on Ubuntu.
Step One: Launch the Terminal from your device by pressing CTRL+ALT+T keys at the same time.
Step Two: Now in the command box, type the command sudo /etc/init.d/dns-clean restart.
Step Three: Now type the command sudo /etc/init.d/networking force-reload.
Now all the DNS cache file will be flushed from Ubuntu. Moreover, if the issues you were facing because of the DNS should be solved now.
Bonus Tip: Configure DNS Settings in Ubuntu
Above, we have discussed how to flush DNS cache Linux to get rid of problems caused by DNS. There are users who want to modify the DNS settings in certain cases. Changing the DNS settings using GUI or the Terminal, it will only take a few minutes. Here is how to do that;
Changing DNS Settings by the Terminal
For users who think Terminal is a convenient way to change DNS settings, and want to know how to change DNS settings, here it is. You can easily change DNS settings by just adding the nameservers to the dnsmasq file. If you don’t have a dnsmasq file installed on your machine, you will need to install it first though the Terminal entering the command sudo apt-get install dnsmasq. Now follow the steps below;
- Once the dnsmasq config file is installed, you need to type the command sudo nano/etc/dnsmasq.conf to edit the file.
- Now you will see the field, which reads ADD OTHER NAMESERVERS HERE, where you can add DNS servers and IP addresses.
Changing DNS Settings by the GUI
Although you can change DNS settings from the Terminal, it is a more straightforward process to do that using the GUI. Users who are using multiple connections will be required to change the DNS settings for each separately. Here is how you can change DNS settings from the GUI;
- Go to the System Settings of your machine.
- Click on the Network option.
- Now click on the ARROW, which you can find next to the name of the network you are using.
- Click the Settings option.
- Now the Settings window will open of the network you are connected with.
- Click on the IPv4 tab.
- Now you will see the ADDITIONAL DNS SERVERS option. You have the option to add DNS servers you want in the given field. For adding multiple servers, you should use commas to separate each of them.
- Click on the Save button.
Linux users who are facing issues because of DNS, such as sluggish website web page loading, etc. flushing DNS cache on Linux is a good option. It will solve all the issues related to DNS, and you will be able to load web pages properly. If you are looking for a guide on how to flush DNS on Linux, above, we have stated multiple methods that will surely help you. For queries, feel free to contact us using the comment section below.
- Quillbot Uses AI to Rephrase Whole Sentences Without Altering Their Meaning
- What are the Chrome Components?
Q: Can I clear DNS cache from the Terminal?
Ans: To flush DNS cache files in Linux, you need to launch its Terminal by pressing CTRL+ALT+T keys. There you can use the command we have mentioned above to flush DNS in Linux.
Q: Why Flushing DNS on Linux is useful?
Ans: Flushing DNS on Linux has various advantages. You will be able to solve problems related to network connectivity, and that is occurred by incorrect and invalid DNS cache files. It will also allow your web browser to load web pages properly.
Q: Does Flushing DNS on Linux cause any harm?
Ans: No, Flushing DNS on Linux is an entirely safe process, and it doesn’t create a new issue.