How to clear DNS query cache in Linux/Unix/Mac

Source: Internet
Author: User

How to clear DNS query cache in Linux/Unix/Mac

In Linux, I use a dial-up connection to access the Internet. Frequent dial-up disconnections cause DNS problems. How can I clear the DNS Cache using shell commands in Linux/Unix distributions?

In MS-Windows, you can use the ipconfig command to clear the dns cache. However, Linux and Unix provide different methods to clear the cache. In Linux, you can run nscd, BIND, or dnsmasq as the name service cache daemon. Large or Working Group servers may use BIND or dnsmasq as dedicated cache servers to accelerate queries.

How to: Clear the nscd dns Cache

Nscd caches the name service request initiated by libc. If NSS data retrieval is considered as slow, nscd can significantly accelerate the speed of continuous access to the same data and improve the performance of the entire system. You only need to restart nscd to refresh the cache:

  1. $ Sudo/etc/init. d/nscd restart

Or

  1. # Service nscd restart

Or

  1. # Service nscd reload

This daemon provides high-speed cache for the most common name service requests. The default configuration file/etc/nscd. conf determines the action of the cache daemon.

Clear dnsmasq dns Cache

Dnsmasq is a lightweight DNS, TFTP, and DHCP server. It aims to provide paired DNS and DHCP services for the LAN. Dnsmasq accepts DNS queries and responds to them from a small local cache or forwards them to a real recursive DNS server. The software is also installed on many cheap routers to cache DNS queries. You only need to restart the dnsmasq service to clear the DNS Cache:

  1. $ Sudo/etc/init. d/dnsmasq restart

Or

  1. # Service dnsmasq restart
Clear the dns cache of the BIND Cache Server

One BIND Cache Server obtains information from another server (regional master) in response to host queries, and then saves (caches) data to the local device. All you need 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 the caches:

  1. # Rndc restart

Or

  1. # Rndc exec

BIND v9.3.0 and later versions support a command to clear the cache of all records for a specific domain name: rndc flushname. In this example, refresh all records of the cyberciti. biz domain:

  1. # Rndc flushname cyberciti. biz

You can also clear the BIND View. For example, you can run the following command to clear the LAN and WAN views:

  1. # Rndc flush lan
  2. # Rndc flush wan
Prompt to Mac OS X Unix users

Run the following command as the root user on Mac:

  1. # Dscacheutil-flushcache

Or

  1. $ Sudo dscacheutil-flushcache

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

  1. Lookupd-flushcache
A message about the/etc/hosts file

/Etc/hosts is used as a static query host table. You need to remove and/or update it in a Unix-like operating system as required:

  1. # Vi/etc/hosts
Sample output:
  1. 127.0.0.1 localhost
  2. 127.0.1.1 wks01.WAG160N wks01
  3. # The following lines are desirable for IPv6 capable hosts
  4. : 1 ip6-localhost ip6-loopback
  5. Fe00: 0 ip6-localnet
  6. Ip6-mcastprefix ff00: 0
  7. Ff02: 1 ip6-allnodes
  8. Ff02: 2 ip6-allrouters
  9. 10.37.34.2 build
  10. 192.168.1.10 nas01
  11. 192.168.1.11 nas02
  12. 192.168.1.12 nas03
  13. #192.168.2.50 nfs2.nixcraft.net. in nfs2
  14. #192.168.2.51 nfs1.nixcraft.net. in nfs1
  15. 17.0232.50 nfs1.nixcraft.net. in nfs1
  16. 17.0232.51 nfs2.nixcraft.net. in nfs2
  17. 192.168.1.101 vm01
Reference

Related: Clear DNS Cache using ipconfig command in Windows Vista/XP

Via: http://www.cyberciti.biz/faq/rhel-debian-ubuntu-flush-clear-dns-cache/

Translator: geekpi Proofreader: wxy

This article was originally translated by LCTT and launched with the Linux honor in China

This article permanently updates the link address:

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: info-contact@alibabacloud.com 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.