
How to Flush DNS Cache on Linux (Ubuntu 24.04, Debian & RHEL)
Clean guide to flush DNS cache on Linux with resolvectl flush-caches (systemd-resolved), dnsmasq, and nscd with verification commands.
Manage hosts files without the terminal
ToggleHosts helps you manage environments visually on Windows, macOS, and Linux, with automatic DNS flush and backups.
One-time payment
Need to flush the DNS cache on Linux? If your system uses systemd-resolved, run:
sudo resolvectl flush-cachesUse it after editing /etc/hosts, changing resolvers, or testing a migration when a hostname still resolves to an old IP. Need every platform in one place? See how to flush the DNS cache on Windows, macOS and Linux.
Linux DNS flush commands by distribution
| Linux Distribution / Resolver | Command | Status / Check |
|---|---|---|
| Ubuntu 22.04 / 24.04 (systemd-resolved) | sudo resolvectl flush-caches | resolvectl statistics |
| Older systemd-resolved | sudo systemd-resolve --flush-caches | systemd-resolve --statistics |
| Any system using nscd | sudo systemctl restart nscd | sudo nscd -g |
| dnsmasq local service | sudo systemctl restart dnsmasq | journalctl -u dnsmasq |
| BIND (named) | sudo rndc flush | sudo rndc status |
How to flush DNS on Linux
To flush DNS on Linux, run the command for your resolver:
- systemd-resolved (most modern distros):
sudo resolvectl flush-caches. - Older systemd:
sudo systemd-resolve --flush-caches. - nscd:
sudo systemctl restart nscd(orsudo nscd -i hosts). - dnsmasq:
sudo systemctl restart dnsmasq. - Local BIND:
sudo rndc flush.
Then verify with resolvectl query myproject.test or dig myproject.test.
Does Linux even cache DNS?
Plain glibc has no DNS cache, so editing /etc/hosts takes effect immediately. A cache exists only when you run a caching layer: systemd-resolved, nscd, dnsmasq, or a local resolver. If unsure which you use:
resolvectl status
systemctl is-active systemd-resolved nscd dnsmasqWhen to flush
- You edited
/etc/hostsand a tool still resolves the old IP. - You changed
/etc/resolv.confor your DNS server. - You moved a staging site to a new server before propagation.
For editing the file itself, see how to edit the hosts file on Linux or the Ubuntu-specific guide.
Verify the result
resolvectl query myproject.test
dig myproject.test
getent hosts myproject.testgetent hosts reflects the full name-service stack, including /etc/hosts.
Troubleshooting
- resolvectl not found: your system may not use systemd-resolved; use the nscd/dnsmasq command instead.
- Still cached in the browser: clear the browser DNS cache and retry in a new tab.
- WSL2: flush on the Windows host too with
ipconfig /flushdns.
If you manage many local domains across machines, ToggleHosts keeps hosts entries organized and consistent across Linux, macOS and Windows.
_Last tested: June 2026 on Ubuntu 24.04, Fedora 40 and Debian 12._
Sources and further reading
Frequently Asked Questions
Run sudo resolvectl flush-caches (older systems: sudo systemd-resolve --flush-caches).
Not always. Plain glibc has no cache. Caching exists only if you run systemd-resolved, nscd, dnsmasq, or a local BIND resolver.
Restart the service: sudo systemctl restart dnsmasq (or send SIGHUP to the dnsmasq process).
Use resolvectl query yourdomain.test or dig yourdomain.test and confirm the expected IP.
Related Articles
How to Flush DNS Cache on Windows, macOS & Linux (2026)Flushing DNS & cache
How to Flush DNS Cache on Windows, macOS & Linux (2026)
8 min read
Flush DNS on Windows 10 & 11: ipconfig /flushdns (2026)Flushing DNS & cache
Flush DNS on Windows 10 & 11: ipconfig /flushdns (2026)
3 min read
Flush DNS on Mac: Command for Sequoia, Sonoma & Tahoe (2026)Flushing DNS & cache
Flush DNS on Mac: Command for Sequoia, Sonoma & Tahoe (2026)
6 min read