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 statistics shows how often the DNS cache really hits

Network and access
~/tips/tip-dns-resolvectl-statistics

resolvectl statistics

Prints cache hits, misses and DNSSEC verdicts from systemd-resolved so you can judge the cache.

On most modern Linux machines, systemd-resolved sits between your programs and the DNS server and keeps a local cache. I always wondered how much that cache does, and it turns out resolved counts it for you.

One command prints the counters:

resolvectl statistics
sudo resolvectl reset-statistics

The output has a few blocks. Transactions shows Current Transactions and Total Transactions, how many DNS transactions resolved has handled. Cache shows Current Cache Size, Cache Hits and Cache Misses. DNSSEC Verdicts counts answers as Secure, Insecure, Bogus or Indeterminate. The second command sets all counters back to zero; the man page notes that it needs root.

Here’s how I’d use it. Reset the counters, use the machine normally for an hour, then run resolvectl statistics again. Divide the hits by hits plus misses and you have a hit rate. A low rate isn’t automatically bad (lots of new names, short TTLs), but if you’ve just pointed the machine at a slow resolver, it tells you how many lookups actually go over the wire. A Bogus count above zero is worth a look too: something failed DNSSEC validation, and resolvectl query on the suspect name shows more.

The caveat: resolved only counts what goes through resolved. A browser with its own DNS over HTTPS, a Docker container with its own DNS setting, or a tool that reads a hand-edited /etc/resolv.conf pointing elsewhere never shows up here. The counters also live in memory, so a restart of systemd-resolved starts them at zero again. The command has been in resolvectl since systemd 239.

Further reading: resolvectl(1) man page

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link