brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: resolvectl show-cache lists what systemd-resolved remembers

Systemd
~/tips/tip-dns-resolvectl-show-cache

resolvectl show-cache

Lists the records systemd-resolved has cached, grouped by network scope.

I already knew how to empty the DNS cache on Linux. What I could not do for a long time was look inside it. Newer versions of systemd can show it.

resolvectl show-cache

The manual describes it as showing the current cache content, per scope. A scope is roughly a network link or the global resolver, so the records come grouped by where they were resolved. The command is listed as added in systemd version 254, so it does not exist on an older distribution.

For something a script can read, ask for JSON:

resolvectl show-cache --json=pretty

The accepted modes are short, pretty and off. Pipe it through jq to find one name in a long list.

It is the natural next step after resolvectl statistics, which only says how often the cache is hit. If a name resolves to an address you did not expect, check whether an old answer is still sitting there before you flush it with resolvectl flush-caches.

Caveat: the cache shows the queries your machine has made, which says a lot about what you do. Read it before you paste anything into a forum.

Further reading: resolvectl(1) manual

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link