How to clear the DNS query cache under Linux/unix/mac

Source: Internet
Author: User

I use dial-up connection to the Internet under Linux, frequent dialing disconnection causes the problem of DNS. How do I use shell commands to clear the DNS cache under the Linux/unix release?

Under Ms-windows, you can use the ipconfig command to clear the DNS cache. However, Linux and UNIX provide different ways to clear the cache. Linux can run NSCD or BIND or DNSMASQ as the name Service cache daemon. Large or workgroup servers may use bind or DNSMASQ as a dedicated cache server to speed up queries.

How to: Clear the NSCD DNS cache

NSCD caches the request for the LIBC initiated name service. If retrieving NSS data is considered slow, NSCD can significantly speed up the continuous access to the same data and improve the performance of the entire system. Simply restart NSCD to refresh the cache:



1. # service NSCD Restart


1. # service NSCD Reload

This daemon provides a cache for the most commonly used name service requests. The default configuration file,/etc/nscd.conf, determines the behavior of the cache daemon.

Clear the DNSMASQ DNS cache

DNSMASQ is a lightweight DNS, TFTP, and DHCP server. It is designed to provide paired DNS and DHCP services to the LAN. DNSMASQ accepts DNS queries and answers them from a small local cache or forwards them to a true recursive DNS server. The software is also installed on many inexpensive routers to cache DNS queries. Simply restart the DNSMASQ service to clear the DNS cache:



1. # service DNSMASQ Restart

Clear the DNS cache for the BIND cache server

A bind cache server obtains information from a query from another server (Zone Master) response host, and then saves (caches) the data locally. All you have to do is restart bind to clear its cache:

1. #/etc/init.d/named Restart

You can also use the following RNDC command to clear all caches:

1. # RNDC Restart



BIND v9.3.0 and above supports a command that clears all record caches for a specific domain name: RNDC flushname. In this example, all records for related fields are refreshed:

1. # RNDC Flushname

You can also clear bind View. For example, LAN and WAN view can be cleared with the following command:

1. # RNDC Flush LAN

2. # RNDC Flush Wan

Tips for users of Mac OS X Unix

Under Mac, enter the following command with the root user:

1. # Dscacheutil-flushcache


1. $ sudo dscacheutil-flushcache

If you are using OSX 10.5 or earlier, try the following command:

1. Lookupd-flushcache

A hint about the/etc/hosts file

/etc/hosts is used as a table for static query hosts. You need to remove and/or update it according to your requirements under UNIX-like operating systems:

1. # vi/etc/hosts

Sample Output : localhost wks01. wag160n wks01

3. # The following lines is desirable for IPV6 capable hosts

4.:: 1 ip6-localhost ip6-loopback

5. fe00::0 Ip6-localnet

6. ff00::0 Ip6-mcastprefix

7. Ff02::1 Ip6-allnodes

8. Ff02::2 Ip6-allrouters Build

Ten. nas01 NAS02 Nas03

# NFS2



How to clear the DNS query cache under Linux/unix/mac

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.