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.
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-resolvedsudo journalctl -u systemd-resolved > ~/cache.txtOpen the file with a text editor and search for “CACHE:” to see cached entries.
Viewing nscd cache
sudo strings /var/cache/nscd/hosts | uniqViewing dnsmasq cache
Send USR1 to dnsmasq and capture its log.
sudo pkill -USR1 dnsmasqsudo journalctl -u dnsmasq > ~/cache.txtHow to Flush DNS Cache on Linux
Using systemd‑resolved
sudo resolvectl flush-cachesOn Ubuntu 17.04/18.04 you can also run:
sudo systemd-resolved --flush-cachesFlushing nscd cache
Restart the nscd service or invalidate hosts.
sudo /etc/init.d/nscd restartsudo nscd -i hostsFlushing dnsmasq cache
sudo systemctl restart dnsmasqor
service dnsmasq restartClearing Chrome DNS Cache
Open chrome://net-internals/#dns and click “Clear host cache”.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
