Clear DNS query cache under Linux/Unix/Mac

Under MS-Windows, you can use the ipconfig command to clear the dns cache. However, Linux and Unix provide different methods 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.

Clear DNS query cache under Linux/Unix/Mac Clear DNS query cache under Linux/Unix/Mac

HOWTO: Clear the nscd dns cache

Nscd caches name service requests initiated by libc. If retrieving NSS data is considered slow, nscd can significantly speed up sequential access to the same data and improve overall system performance. Just restart nscd to refresh the cache:

$ sudo /etc/init.d/nscd restart

or

# service nscd restart

or

# service nscd reload

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

clear dnsmasq dns cache

dnsmasq is a lightweight DNS, TFTP and DHCP server. Its purpose is to provide paired DNS and DHCP services to the LAN. dnsmasq takes DNS queries and answers them from a small local cache or forwards them to a true recursive DNS server. This software is also installed on many cheap routers to cache DNS queries. Just restart the dnsmasq service to clear the DNS cache:

$ sudo /etc/init.d/dnsmasq restart

or

# service dnsmasq restart

Clear the dns cache of the BIND cache server

A BIND cache server obtains information from another server (region master) in response to a host's query, and then stores (caches) the data locally. All you have to do is restart BIND to clear its cache:

# /etc/init.d/named restart

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

# rndc restart

or

# rndc exec

BIND v9.3.0 and above support a command to flush all record caches for a specific domain name: rndc flushname. In this example, refresh all records of domains related to cyberciti.biz:

# rndc flushname cyberciti.biz

BIND View can also be cleared as well. For example, the views of LAN and WAN can be cleared with the following command:

# rndc flush lan
# rndc flush wan

Tips for Mac OS X Unix Users

On a Mac, enter the following command as the root user:

# dscacheutil -flushcache

or

$ sudo dscacheutil -flushcache

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

lookupd -flushcache

A note about the /etc/hosts file

/etc/hosts is used as a table for static lookup of hosts. You will need to remove and/or update it according to your requirements on Unix-like operating systems:

# vi /etc/hosts

Example output:

127.0.0.1   localhost
127.0.1.1   wks01.WAG160N   wks01
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
10.37.34.2     build
192.168.1.10    nas01
192.168.1.11    nas02
192.168.1.12    nas03
#192.168.2.50   nfs2.nixcraft.net.in nfs2
#192.168.2.51   nfs1.nixcraft.net.in nfs1
172.168.232.50  nfs1.nixcraft.net.in nfs1
172.168.232.51  nfs2.nixcraft.net.in nfs2
192.168.1.101   vm01

 

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/132516799