Locahl
Buy Locahl
DNSLinuxflush DNSsystemd-resolvedlocal development

Flush DNS on Linux: systemd-resolved & more (2026)

Flush the DNS cache on Linux with resolvectl flush-caches (systemd-resolved), plus nscd, dnsmasq and BIND. Commands by setup, with verification steps.

L

Locahl Team

Β·2 min read

Need to flush the DNS cache on Linux? On modern distributions using systemd-resolved, run:

BASH
sudo resolvectl flush-caches

Use it after editing /etc/hosts, changing resolvers, or testing a migration when a hostname still resolves to an old IP.

How to flush DNS on Linux

To flush DNS on Linux, run the command for your resolver:

1. systemd-resolved (most distros): sudo resolvectl flush-caches. 2. Older systemd: sudo systemd-resolve --flush-caches. 3. nscd: sudo systemctl restart nscd (or sudo nscd -i hosts). 4. dnsmasq: sudo systemctl restart dnsmasq. 5. 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:

BASH
resolvectl status
systemctl is-active systemd-resolved nscd dnsmasq

When to flush

  • You edited /etc/hosts and a tool still resolves the old IP.
  • You changed /etc/resolv.conf or 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

BASH
resolvectl query myproject.test
dig myproject.test
getent hosts myproject.test

getent 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, Locahl keeps hosts entries organized and consistent across Linux, macOS and Windows.

_Last tested: June 2026 on Ubuntu 24.04, Fedora 40 and Debian 12._

Also readHow to edit the hosts file on Linux
Share this article
Available on Windows, macOS & Linux

Ready to simplify your workflow?

Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.

  • Intuitive visual interface
  • Automatic DNS flush
  • Multi-environment management
  • Automatic backups
  • JSON Import/Export
Buy Locahl β€” $5.99One-time payment, no subscription

Reader Reviews

4.7β˜…(3 reviews)
Dmitri V.
β˜…β˜…β˜…β˜…β˜…

"resolvectl flush-caches was exactly what my Ubuntu box needed after editing /etc/hosts."

June 12, 2026

Hannah B.
β˜…β˜…β˜…β˜…β˜…

"Covers systemd-resolved, dnsmasq and nscd β€” finally one page with all the commands."

June 10, 2026

Sven O.
β˜…β˜…β˜…β˜…β˜…

"Helpful. Would like a bit more on NetworkManager dnsmasq."

June 8, 2026

Frequently Asked Questions

How do I flush DNS on Linux with systemd-resolved?

Run sudo resolvectl flush-caches (older systems: sudo systemd-resolve --flush-caches).

Does Linux always cache DNS?

Not always. Plain glibc has no cache. Caching exists only if you run systemd-resolved, nscd, dnsmasq, or a local BIND resolver.

How do I flush dnsmasq?

Restart the service: sudo systemctl restart dnsmasq (or send SIGHUP to the dnsmasq process).

How do I verify the cache was cleared?

Use resolvectl query yourdomain.test or dig yourdomain.test and confirm the expected IP.

Related Articles

6 min read
DNSmacOS Tahoeflush DNS

macOS Tahoe Flush DNS Cache Command

Clear DNS cache on macOS Tahoe 26 with the exact Terminal command, verification steps, browser cache checks and hosts file troubleshooting.

L

Locahl Team

Developer tools team

6 min read
DNSmacOScache

Flush DNS Mac: macOS Cache Command (2026)

Copy the exact macOS flush DNS cache command for Tahoe, Sequoia, Sonoma, Ventura and older versions. Includes browser cache fixes.

L

Locahl Team

10 min read
hosts fileWindowsmacOS

How to Edit the Host File (Windows, Mac & Linux)

Edit the host file on Windows, macOS and Linux: file location, admin rights, syntax, DNS flush, and troubleshooting when changes do not apply.

L

Locahl Team