Operations 7 min read

How to Flush DNS Cache on Linux: A Complete Step‑by‑Step Guide

This article explains why local DNS caches can cause HTTP errors or DNS spoofing, shows how to view caches created by systemd‑resolved, nscd, and dnsmasq, and provides clear command‑line instructions for flushing those caches on Linux systems, including Chrome’s own DNS cache.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Flush DNS Cache on Linux: A Complete Step‑by‑Step Guide

Why Flush DNS Cache on Linux?

Local DNS cache can become corrupted, causing HTTP errors or DNS spoofing; refreshing forces the system to retrieve fresh records.

How to View Local DNS Cache

Before systemd, most Linux distributions lacked a system‑wide DNS cache unless dnsmasq or nscd were installed. systemd‑resolved now provides caching.

Viewing systemd‑resolved cache

Send SIGUSR1 to dump the cache, then use journalctl to save the output.

sudo killall -USR1 systemd-resolved
sudo journalctl -u systemd-resolved > ~/cache.txt

Open the file with a text editor and search for “CACHE:” to see cached entries.

Viewing nscd cache

sudo strings /var/cache/nscd/hosts | uniq

Viewing dnsmasq cache

Send USR1 to dnsmasq and capture its log.

sudo pkill -USR1 dnsmasq
sudo journalctl -u dnsmasq > ~/cache.txt

How to Flush DNS Cache on Linux

Using systemd‑resolved

sudo resolvectl flush-caches

On Ubuntu 17.04/18.04 you can also run:

sudo systemd-resolved --flush-caches

Flushing nscd cache

Restart the nscd service or invalidate hosts.

sudo /etc/init.d/nscd restart
sudo nscd -i hosts

Flushing dnsmasq cache

sudo systemctl restart dnsmasq

or

service dnsmasq restart

Clearing Chrome DNS Cache

Open chrome://net-internals/#dns and click “Clear host cache”.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

CachelinuxDNS
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.