Search Authority

How to Flush DNS in Linux: Quick & Easy Guide

Flushing the DNS cache on Linux helps resolve website resolution issues after network changes or DNS misbehavior. This guide explains why and how to clear DNS entries on differe...

Mara Ellison Jul 25, 2026
How to Flush DNS in Linux: Quick & Easy Guide

Flushing the DNS cache on Linux helps resolve website resolution issues after network changes or DNS misbehavior. This guide explains why and how to clear DNS entries on different environments.

Use the structured overview below to quickly compare methods, understand when each applies, and choose the right approach for your workflow.

nfc
Method When to Use Command Scope
systemd-resolved Systemd-based distros with resolved active sudo systemd-resolve --flush-caches System-wide, managed by resolved
nscd Older setups using Name Service Cache Daemon sudo /etc/init.d/nscd restart System-wide, managed by nscd
dnsmasq Local dnsmasq used by desktop or router scripts sudo /etc/init.d/dnsmasq restart System-wide or per-interface depending on setup
resolvectl Modern systemd environments exposing cache stats sudo resolvectl flush-caches System-wide via systemd-resolved
manual cache delete Stubborn entries when daemons lack flush support sudo rm -f /var/cache/samba/* (example paths vary) Advanced, daemon-specific, risky if misused

systemd resolved flush methods

On modern Linux desktops and servers, systemd-resolved is the default DNS manager. When you change DNS servers or face stale entries, flushing its cache is the first step to force fresh lookups.

Use the following command to flush DNS in systems managed by systemd-resolved. This tells the daemon to discard cached negative and positive entries immediately.

For systems with resolvectl available, the flush operation is straightforward. You can also query cache statistics before and after flushing to confirm that cached records are cleared.

nscd dns cache restart process

Name Service Cache Daemon (nscd) is still present on some legacy or minimal Linux deployments. It caches passwd, group, and DNS responses, which can hold outdated DNS data.

Restarting nscd clears its in-memory cache, including DNS entries, and reloads configuration from disk. Use service management commands or direct init scripts depending on your platform.

Because nscd is increasingly replaced by systemd-resolved, prefer native tools when available. Reserve nscd restarts for environments where it is explicitly installed and required.

dnsmasq flush and restart guidance

Many lightweight routers and development environments run dnsmasq to handle local DNS and DHCP. Dnsmasq can cache records, so a restart is required to purge those entries.

On init systems that support it, restart dnsmasq cleanly with its standard command. Verify that the service is active and check logs if resolution issues persist after the restart.

If dnsmasq is configured per interface, target the specific service unit to avoid impacting unrelated network functions. Always review configuration files for custom cache size settings.

best practices for DNS cache maintenance

Adopting a routine for DNS cache management reduces downtime after network reconfigurations and improves reliability across Linux hosts.

  • Prefer systemd-resolved flush commands on modern distributions
  • Verify cache status before and after flushing to confirm effectiveness
  • Restart only the relevant DNS daemon to limit service impact
  • Document the DNS strategy for each host, including cache settings
  • Schedule non-disruptive maintenance windows for cache clearing in production

FAQ

Reader questions

How do I know which DNS cache mechanism is active on my Linux host?

Run systemctl to check the status of systemd-resolved, nscd, and dnsmasq. The active daemon determines which flush method you should use. Prefer systemd-resolved commands when resolved is running.

Will flushing DNS disrupt other network services on Linux?

Flushing the cache is safe and typically causes only brief additional resolution latency while fresh records are fetched. Restarting daemons briefly interrupts cached name resolution but does not break existing connections.

What should I do if DNS resolution still fails after clearing the cache on Linux?

Check resolver configuration in /etc/resolv.conf, ensure the chosen DNS servers are reachable, and review application-specific DNS settings. Corrupted cache files or restrictive firewall rules can also cause persistent resolution failures.

Can I flush DNS for a single application instead of system-wide on Linux?

Linux does not offer per-application DNS cache flush through standard daemons. Use containers, network namespaces, or dedicated DNS forwarders if you need isolated DNS behavior separate from the system cache.

Related Reading

More pages in this topic cluster.

How to Tell the Difference Between Silver and Aluminum (Silver vs Aluminum)

Spotting the difference between silver and aluminum helps you verify purchases, appraise items, and avoid overpaying for misidentified metals. While they look similar at first g...

Read next
Excel Keyboard Shortcut for Strikethrough: Easy Step-by-Step Guide

Mastering the Excel keyboard shortcut for strikethrough helps you track completed tasks, revisions, and action items without leaving the keyboard. This small efficiency habit sp...

Read next
Durham NC News Today: Latest Headlines & Updates

Durham NC news keeps the Research Triangle region informed about breakthrough healthcare, education, and downtown development. Local reporting connects residents and visitors to...

Read next