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.
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
Why these commands
DNS caching is a performance optimization: your OS stores the results of DNS lookups so it doesn’t have to ask the DNS server every time you connect to the same hostname. The cache respects each record’s TTL (time-to-live), which can be anywhere from 60 seconds to 24 hours. This works seamlessly when DNS records are stable. It breaks when you change something and the old answer is still in cache.
In a homelab, DNS changes happen constantly. You move a service to a new LXC, you update Pi-hole entries, you add a new hostname to your internal DNS server. Every time, the same problem: you made the change on the server, but your laptop is still connecting to the old address because it cached the previous lookup. Flushing the cache forces a fresh lookup on the next request and cuts through that confusion immediately.
The commands differ significantly by operating system because DNS resolution is implemented differently on each. Linux uses either systemd-resolved (the standard on Ubuntu, Debian, Fedora, and openSUSE since 2018) or the older nscd daemon on distributions that don’t use systemd’s resolver. macOS uses its own mDNSResponder daemon, flushed by a combination of dscacheutil and a HUP signal. Windows uses the ipconfig command. Knowing which one your system uses before running commands is important — running the wrong command either does nothing or errors silently.
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-resolvedis the standard resolver on all major distros since 2018; ifresolvectlis 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