Home >System Tutorial >LINUX >Clear DNS query cache on Linux/Unix/Mac

Clear DNS query cache on Linux/Unix/Mac

王林
王林forward
2023-12-30 22:59:30650browse
Introduction Under MS-Windows, you can use the ipconfig command to clear the dns cache. However, Linux and Unix provide different methods to clear 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.

在 Linux/Unix/Mac 下清除 DNS 查询缓存

How to: clear nscd dns cache

Nscd will cache name service requests initiated by libc. If retrieving NSS data is considered slow, nscd can significantly speed up consecutive accesses to the same data and improve the performance of the entire system. Just restart nscd to flush the cache:

$ sudo /etc/init.d/nscd restart

or

# service nscd restart

or

# service nscd reload

This daemon provides a cache for the most commonly used name service requests. The default configuration file /etc/nscd.conf, which 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 local area network. dnsmasq accepts DNS queries and answers them from a small local cache or forwards them to a real 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 the host's query, and then saves (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 clear the cache of all records for a specific domain name: rndc flushname. In this example, refresh all records of cyberciti.biz related domains:

# rndc flushname cyberciti.biz

BIND View can also be cleared. For example, LAN and WAN Views can be cleared with the following command:

# rndc flush lan
# rndc flush wan
Tips for Mac OS X Unix users

Enter the following command as root user on Mac:

# dscacheutil -flushcache

or

$ sudo dscacheutil -flushcache

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

lookupd -flushcache

A tip about the /etc/hosts file

/etc/hosts is used as a table to statically query hosts. You need to remove and/or update it according to your requirements under a Unix-like operating system:

# 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

The above is the detailed content of Clear DNS query cache on Linux/Unix/Mac. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete