Estimate hostname resolution latency across DNS, /etc/hosts and cache lookup layers.
Hostname resolution on Linux is governed by /etc/nsswitch.conf's 'hosts:' line, which typically checks local sources (files, i.e. /etc/hosts) before falling back to dns, with a local resolver cache (systemd-resolved, nscd) short-circuiting repeated lookups. Average resolution time is dominated by the (usually tiny) cache check cost most of the time, plus the full DNS round-trip cost only on the fraction of lookups that miss the cache — meaning even a fast cache with a high miss rate can leave average latency close to full DNS query time.
Average resolution time
time = cache_check + (miss_rate × dns_query_time)
`cat /etc/nsswitch.conf | grep ^hosts` shows the configured order (e.g. 'hosts: files dns'), meaning /etc/hosts is checked before falling back to DNS. Some distros insert `mdns4_minimal` or `resolve` (for systemd-resolved) into this chain.
`time getent hosts <hostname>` measures a single resolution round-trip end-to-end through the full nsswitch chain; running it twice in a row highlights the cache-hit speedup versus the first (likely cache-miss) lookup.
A high miss rate typically means the workload queries a large number of distinct, rarely-repeated hostnames (common in microservice service-discovery churn or short-TTL cloud DNS records) faster than entries can be reused before expiring — increasing cache capacity doesn't help if the working set of names genuinely exceeds what gets repeated.