How to clean/delete DNS Cache in Manjaro Linux?

In windows
we use ipconfig /flushdns in cmd(command prompt)
so how to do it in Manjaro linux

Hi @Nightpanda, and welcome!

I’ve never don it myself, but according to this page:

Flush DNS using systemd-resolved

The easiest way to flush the DNS on Linux, if you are using systemd-resolved, is to use the systemd-resolv command followed by --flush-caches.

Alternatively, you can use the resolvectl command followed by the flush-caches option.

$ sudo systemd-resolve --flush-caches

$ sudo resolvectl flush-caches

So give that a go:

sudo systemd-resolve --flush-caches

Hope this helps!

1 Like

didnt know this before, apparently arch has no dns cache by default (if you are not using systemd-resolved). is this still true?

I didn’t know this, either. But looking at systemctl status systemd-resolved.service:

$ systemctl status systemd-resolved.service
○ systemd-resolved.service - Network Name Resolution
Loaded: loaded (/usr/lib/systemd/system/systemd-resolved.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd-resolved.service(8)
man:org.freedesktop.resolve1(5)
https://www.freedesktop.org/wiki/Software/systemd/writing-network-configuration-managers
https://www.freedesktop.org/wiki/Software/systemd/writing-resolver-clients

I see that it’s inactive. So it would seem so.

Manjaro defaults to use openresolv

man resolvconf

The equivalent of the windows command would be

resolvectl flush-caches
4 Likes

Here is quick overview from Wikipedia that gives you an idea about where DNS caches reside:

However, the Linux TCP/IP stack does not come with a DNS cache. So if you want to cache DNS request on a Linux system, you will need to install a DNS resolver with caching function. Popular examples are: nscd, dnsmasq, unbound

Manjaro doesn’t seem to use any of these and therefore doesn’t seem to have a DNS cache in the OS layer:

Your applications (for example browsers) might still come with their own DNS cache. I would not expect applications to cache DNS requests on disk (for performance and other reasons), so you can likely flush the application’s DNS cache by restarting the app.

when i type this command sudo systemd-resolve
*** too few arguments**
and when i type this sudo resolvectl flush-caches
*failed to flush caches: unit dbus-org.freedesktop.resolve1.service not found

See @linux-aarhus’s answer:

This command does not work. I’ve tried without and without sudo. Any other suggestions would be greatly appreciated

    ~  resolvectl flush-caches                             ✔ 
Failed to flush caches: Unit dbus-org.freedesktop.resolve1.service not found.
    ~  sudo resolvectl flush-caches                      1 ✘ 
[sudo] password for whacker: 
Failed to flush caches: Unit dbus-org.freedesktop.resolve1.service not found.

You need to use systemd-resolved otherwise the flush-caches command has no effect.

If you want to use systemd-resolved enable it and make sure it is correctly configured.

See the arch wiki for more information on systemd-resolved.
systemd-resolved - ArchWiki (archlinux.org)

2 Likes

@Nightpanda
You can have NetworkManager
(if that is what you use - it is the default for most Manjaro variants)
use dnsmasq
as a resolver.

Simply create a file:
/etc/NetworkManager/conf.d//dns.conf
with the content:

[main]
dns=dnsmasq

Then you have dns caching and can use the procedure for dnsmasq to clear the cache if desired.
I do use this.
It can create issues (and has to be disabled) with certain vpn’s
(Mullvad VPN, for example - the instructions explicitely state to disable this).
When I use Mullvad VPN (from time to time)
I must remember to disable that NetworkManager configuration (comment it out).

1 Like