How to view and clear BIND DNS server cache?

In this article we will see how to view and clear BIND DNS server cache.

bind9

A DNS server can cache the DNS records which was previously looked up, in its cache. Usually it stores the cache data in RAM. You can view or flush this cache if needed. This is useful when you have made some changes in your DNS records and you want your DNS server get updated records instantly.

How to view the DNS cache inside BIND server

We can dump the in memory cache of DNS records maintained by BIND server using following command

The above command will dump the cache into file /var/cache/bind/named_dump.db . This file name/location is configurable. Please refer the BIND configuration parameter ( inside named.conf file)

On my machine its configured to “/var/named/data/cache_dump.db” , you can change it if needed.

Now you view the cached dns records by using linux commands “cat” or “less”

Consider you have used dnslookup for domain “yahoo.com” before dumping the cache. Now you can see the cached dns entries using

How to  flush the cached dns records in BIND

Use the following command

and then reload BIND

To verify cache has been removed, you can dump the cache again and check the file

You can see that cached dns records are gone.

Leave a Reply

Your email address will not be published. Required fields are marked *