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: prefetch: yes keeps popular names in the Unbound cache

Unbound
~/tips/tip-unbound-prefetch-yes

prefetch: yes

Refreshes popular DNS entries just before they expire so repeat lookups stay fast.

A cached DNS answer is fast. The first lookup after it expires is not. Unbound has a setting that renews popular entries before that happens.

server:
    prefetch: yes

The unbound.conf docs say it like this: with prefetch: yes, a cache hit on an entry that is in the last 10 percent of its TTL triggers a prefetch, which keeps the cache up to date. Names you ask for often don’t expire from the cache. The default is no.

Check the file and then reload:

unbound-checkconf
unbound-control reload_keep_cache

Plain reload flushes the cache and reads the config fresh. reload_keep_cache tries to keep the cache, if the new configuration allows it.

The caveat is in the docs as well: it costs about 10 percent more traffic and load on the machine. On a home network that is nothing. There is a related prefetch-key option that fetches DNSKEYs earlier during validation, at a little extra CPU.

Prefetch only helps names that get asked for again before they expire, since a cache hit is what triggers it. The docs list cache-min-ttl (default 0, disabled) as a separate setting for a minimum time to live in the cache, and serve-expired (default no) for serving old responses from the cache. Those are different tools for different problems.

Further reading: Unbound docs: unbound.conf, Unbound docs: unbound-control

Going deeper: Guide: AdGuard Home with Unbound: resolve DNS yourself instead of asking Cloudflare or your ISP

More Unbound tips unbound-control cache_lookup example.com unbound-checkconf /etc/unbound/unbound.conf All Unbound tips (3) All topics

Link