+5 votes
301 views
How to clean DNS Cache Linux

in Linux / Unix by (552k points)
reopened | 301 views

1 Answer

+3 votes
Best answer

1. Clear DNS cache using systemd-resolve on Linux
2. Clear DNS cache using dnsmasq or named in Linux

The DNS server (Domain Name System) has been created in order to translate domain names into IP addresses and vice versa in order to make it possible to send data packets to the destination computers. Each time we enter an address In the web browser, the team is responsible for sending a query to the registered DNS server , requesting the IP address that is associated with the searched domain name, this search takes time and if it is carried out in each access process, the DNS server It can handle a large number of requests that can eventually cause a collapse of this and its consequent result is access denied..

To avoid this, there is the DNS cache which is responsible for saving the IP address of that domain locally in order to skip the search process in the next access, but is redirected taking this local value and thus free loading the server and at the same time we access much faster. But the problem is that having too much DNS cache hosted can affect the browser's own performance, so its release is recommended, let's see how to do this task in Linux.

To keep up, remember to subscribe to our YouTube channel! SUBSCRIBE


1. Clear DNS cache using systemd-resolve on Linux


The Ubuntu and other Debian-based distributions make use of the systemd-resolve command, this command is a DNS daemon integrated in systemd, and is a system service that provides network name resolution to local applications.

This command implements a cache and validation of DNS / DNSSEC stub resolve, as well as an LLMNR and MulticastDNS resolve. Local applications are able to send network name resolution requests through three interfaces:

  • The native API with all the functions of the system solved is exposed on the bus.
  • The glibc getaddrinfo API which is defined by RFC3493 and its related resolution functions, including gethostbyname.
  • A local DNS stub listener is offered at the IP address 127.0.0.53 in the local loopback interface, from there the programs that generate DNS requests directly, avoiding local APIs, can use this auxiliary code, to connect to systemd-resolved
Step 1

To use this command first we will see the DNS cache statistics in the system:
 sudo systemd-resolve –statistics 
image
Step 2

Now, to clear the DNS cache we execute:
 sudo systemd-resolve --flush-cachres 
image
Step 3

As we can see, executing the statistic has deleted the DNS cache. This is the most common method. Other options to use for different distributions are:
In case of using RedHat or ArchLinux
 sudo systemctl restart nscd 

2. Clear DNS cache using dnsmasq or named in Linux


Next we will see two other options to clear the cache
Clear DNS cache with Dnsmasq
Dnsmasq is frequently used on local DNS servers or routers, to clear the DNS cache with this command we must execute:
 sudo systemctl restart dnsmasq 
Clear DNS cache with BIND
This BIND command is used for DNS servers specially designed for specific tasks and to clear the DNS cache there, just run:
 sudo systemctl restart named 

It's that simple that we have cleared the Linux DNS cache thus improving the performance of our equipment through the terminal..


by (3.5m points)
edited

Related questions

+3 votes
1 answer
asked Dec 6, 2019 in Linux / Unix by backtothefuture (552k points) | 275 views
+5 votes
1 answer
+5 votes
1 answer
asked Oct 8, 2019 in Mac by backtothefuture (552k points) | 290 views
+5 votes
1 answer
asked Apr 6, 2021 in Windows 10 by backtothefuture (552k points) | 145 views
+5 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users