Multi-platformnetworkingTested on real hardware

Flush the DNS cache (Linux / macOS / Windows)

Clear the local DNS resolver cache on Linux, macOS, and Windows. Fixes stale DNS records after changing a hostname, IP, or internal DNS entry.

Shellbash
Updated
Script
bash
# ── Linux (systemd-resolved — Ubuntu 18.04+, Debian 12+, Fedora, openSUSE) ──
sudo resolvectl flush-caches
resolvectl statistics | grep -A3 "Cache"

# ── Linux (nscd — older distros or those using nscd instead of resolved) ─────
# sudo systemctl restart nscd

# ── Linux (dnsmasq — if running as local resolver) ──────────────────────────
# sudo systemctl restart dnsmasq

# ── macOS (Monterey 12+, Ventura 13, Sonoma 14) ─────────────────────────────
# sudo dscacheutil -flushcache
# sudo killall -HUP mDNSResponder

# ── Windows (Command Prompt or PowerShell — no elevation required) ───────────
# ipconfig /flushdns

When to use this

Flush the DNS cache when:

  • You updated an IP address in your router, Pi-hole, or internal DNS server and the old address is still resolving
  • A hostname stopped resolving after a config change
  • You’re testing DNS changes and need to force a fresh lookup
  • You moved a service to a new IP and clients are still hitting the old one

Linux

systemd-resolved (Ubuntu 18.04+, Debian 12+, Fedora 33+, openSUSE Leap 15.3+)

sudo resolvectl flush-caches

Verify the cache was cleared:

resolvectl statistics | grep -A3 "Cache"
# Current Cache Size should drop to 0

Check which resolver is active on your system:

systemctl is-active systemd-resolved

nscd (older distros)

sudo systemctl restart nscd

dnsmasq (if used as a local resolver)

sudo systemctl restart dnsmasq
# or send SIGHUP to reload without full restart:
sudo kill -HUP "$(cat /var/run/dnsmasq/dnsmasq.pid)"

Check which resolver your system uses

resolvectl status | head -20    # systemd-resolved
cat /etc/resolv.conf            # shows active nameservers

macOS

Works on Monterey (12), Ventura (13), and Sonoma (14):

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Both commands are required — dscacheutil clears the DNS cache, and killall -HUP mDNSResponder signals the mDNS responder to discard its records.

Confirm it worked:

dscacheutil -statistics

Windows

Run in Command Prompt or PowerShell — no administrator elevation required:

ipconfig /flushdns

You should see: Successfully flushed the DNS Resolver Cache.

Additional DNS commands:

ipconfig /displaydns          # show current cache contents before flushing
ipconfig /registerdns         # re-register DNS records with the DHCP server
nslookup hostname 8.8.8.8     # test resolution against a specific DNS server

Test that your change is resolving correctly

After flushing, confirm the new record is live:

# Linux / macOS
nslookup hostname
dig hostname

# Windows
nslookup hostname
Resolve-DnsName hostname

If the old IP still appears, the TTL on the upstream DNS record hasn’t expired yet — the TTL is set by your DNS server, not your local cache.

Notes

  • The local DNS cache stores results for the duration of each record’s TTL — flushing just forces a fresh lookup on the next query; it doesn’t change what the upstream server returns
  • On Linux, systemd-resolved is the standard resolver on all major distros since 2018; if resolvectl is not found, your distro uses a different resolver
  • Pi-hole users: flush the Pi-hole cache separately via the Pi-hole admin UI or pihole restartdns