search
HomeSystem TutorialLINUXClear DNS query cache on Linux/Unix/Mac

Clear DNS query cache on Linux/Unix/Mac

Dec 30, 2023 pm 10:59 PM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

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:Linux就该这么学. If there is any infringement, please contact admin@php.cn delete
How does process management differ between Linux and Windows?How does process management differ between Linux and Windows?May 04, 2025 am 12:04 AM

The main difference between Linux and Windows in process management lies in the implementation and concept of tools and APIs. Linux is known for its flexibility and power, relying on kernel and command line tools; while Windows is known for its user-friendliness and integration, mainly managing processes through graphical interfaces and system services.

What are the typical use cases for Linux versus Windows?What are the typical use cases for Linux versus Windows?May 03, 2025 am 12:01 AM

Linuxisidealforcustomization,development,andservermanagement,whileWindowsexcelsineaseofuse,softwarecompatibility,andgaming.Linuxoffershighconfigurabilityfordevelopersandserversetups,whereasWindowsprovidesauser-friendlyinterfaceandbroadsoftwaresupport

What are the differences in user account management between Linux and Windows?What are the differences in user account management between Linux and Windows?May 02, 2025 am 12:02 AM

The main difference between Linux and Windows in user account management is the permission model and management tools. Linux uses Unix-based permissions models and command-line tools (such as useradd, usermod, userdel), while Windows uses its own security model and graphical user interface (GUI) management tools.

How does the command line environment of Linux make it more/less secure than Windows?How does the command line environment of Linux make it more/less secure than Windows?May 01, 2025 am 12:03 AM

Linux'scommandlinecanbemoresecurethanWindowsifmanagedcorrectly,butrequiresmoreuserknowledge.1)Linux'sopen-sourcenatureallowsforquicksecurityupdates.2)Misconfigurationcanleadtovulnerabilities.Windows'commandlineismorecontrolledbutlesscustomizable,with

How to Make a USB Drive Mount Automatically in LinuxHow to Make a USB Drive Mount Automatically in LinuxApr 30, 2025 am 10:04 AM

This guide explains how to automatically mount a USB drive on boot in Linux, saving you time and effort. Step 1: Identify Your USB Drive Use the lsblk command to list all block devices. Your USB drive will likely be labeled /dev/sdb1, /dev/sdc1, etc

Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Best Cross-Platform Apps for Linux, Windows, and Mac in 2025Apr 30, 2025 am 09:57 AM

Cross-platform applications have revolutionized software development, enabling seamless functionality across operating systems like Linux, Windows, and macOS. This eliminates the need to switch apps based on your device, offering consistent experien

Best Linux Tools for AI and Machine Learning in 2025Best Linux Tools for AI and Machine Learning in 2025Apr 30, 2025 am 09:44 AM

Artificial Intelligence (AI) is rapidly transforming numerous sectors, from healthcare and finance to creative fields like art and music. Linux, with its open-source nature, adaptability, and performance capabilities, has emerged as a premier platfo

5 Best Lightweight Linux Distros Without a GUI5 Best Lightweight Linux Distros Without a GUIApr 30, 2025 am 09:38 AM

Looking for a fast, minimal, and efficient Linux distribution without a graphical user interface (GUI)? Lightweight, GUI-less Linux distros are perfect for older hardware or specialized tasks like servers and embedded systems. They consume fewer res

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft