Field Notes

Tracking down a slow DNS lookup

October 21, 2025

The symptom was a command that paused for a few seconds before doing anything, every single time. A delay that is almost exactly the same on every run usually means a timeout, and in this kind of problem the timeout is often a DNS query.

Measure the lookup the way programs do

time getent hosts example.org

getent uses the system resolver, the same path most programs take. Tools like dig talk to a name server directly and can look fast while your application is slow.

Check what is configured

cat /etc/resolv.conf
resolvectl status

Look at the list of name servers. If the first one is unreachable, each lookup waits for it to time out before trying the next. That alone explains a constant delay.

IPv6 and search domains

Fixing it

Remove or reorder the dead name server, or point the machine at one that answers quickly. After that the delay went away for me, and time getent hosts dropped to a few milliseconds.

← All notes