Insights

How to clear the DNS cache on Linux

Use resolvectl flush-caches for systemd-resolved or send SIGHUP to the dnsmasq instance in use. Skip the flush if there's no local cache.

Illustration of address-card carousel with empty pockets.
On this page

On Linux, run resolvectl flush-caches if your Domain Name System (DNS) lookups use systemd-resolved. If they use a local dnsmasq cache, send the hang-up signal (SIGHUP) to the dnsmasq instance that handles the lookup. If there's no local cache in the lookup path, there's nothing to flush on your device.

In short:

  • systemd-resolved. Use resolvectl flush-caches for lookups through this service.
  • Local dnsmasq. Send SIGHUP only to the instance handling the lookup.
  • No local cache. Skip the flush for that lookup.

Pick the command for your resolver

1. Check which resolver handles the lookup.

On Linux, start with the hostname that returns the wrong answer and the app where you saw it. Check systemd-resolved's current settings:

resolvectl status

Open /etc/resolv.conf and check which addresses appear on its nameserver lines. Use those addresses and the service settings to work out where the lookup goes, then check whether the affected app uses its own resolver. A running service or a local nameserver address doesn't prove the app uses that service or that caching is on.

2. Flush the cache if the lookup uses systemd-resolved.

This command clears all DNS records cached by systemd-resolved. To check whether the cache is returning one old answer before clearing it, run the two lookups in the next section first.

resolvectl flush-caches

For dnsmasq, use the next command only if you've confirmed that the standalone unit is dnsmasq.service and its main process is the instance handling your lookup. If dnsmasq runs inside another service or you can't confirm the instance, don't substitute a signal to all dnsmasq processes.

SIGHUP also reloads local data such as /etc/hosts and can run the Dynamic Host Configuration Protocol (DHCP) lease change script. On a shared service, proceed only if you're authorized and have a recovery plan.

3. Signal the confirmed standalone dnsmasq instance.

sudo systemctl kill --kill-whom=main --signal=SIGHUP dnsmasq.service

4. Skip the flush if you've confirmed there's no local cache.

If you haven't identified the resolver, check the app and resolver settings before guessing at a command or restarting networking.

Look up the same name again

Before flushing systemd-resolved, you can compare two lookups on Linux if your version supports --cache=no. Replace example.com in both commands with the affected hostname.

1. Run a normal lookup that can use the local cache.

resolvectl query example.com

2. Look up the same name without using the local cache.

resolvectl --cache=no query example.com

If only the second lookup returns the expected address, the local cache may be the source of the old answer. If both return the old address, clearing that cache alone won't change what the second lookup returns.

3. Repeat the original lookup after the flush.

Once the matching command finishes without an error, repeat the lookup with the same tool and hostname. Check for the expected address, then retry the affected app if you tested the resolver separately. A flush command that finishes without an error doesn't tell you whether the answer has changed.

Check where the old answer comes from

A local flush leaves upstream caches and separate app caches alone. If the lookup still returns the old address when you skip the local cache, check what your configured upstream resolver returns. That's the server your local resolver sends queries to, and skipping the local cache doesn't force it to fetch a fresh answer.

If the resolver test returns the expected address but the app still shows the old one, check the app's own cache and resolver settings.

Where doxx.net fits. doxx.net encrypts DNS lookups and blocks unwanted domains. If you also want to change how your lookups are handled, you can download the doxx.net app.

Ask an AI assistant

Share this article

Private Everywhere

Stop giving the internet everything

Keep your browsing, messages, files, and agents private.