Linux · Systems fluency

How does DNS resolution work on Linux?

Mediumdnsresolv.confnsswitchUpdated Oct 2026
Quiz this track

Short answer

Name resolution follows the NSS configuration, usually checking /etc/hosts before DNS. The resolver reads nameservers and search domains, then queries them, with caching layers such as systemd-resolved or nscd depending on the system.

Applications rarely talk to DNS directly. They call getaddrinfo, which consults /etc/nsswitch.conf and may use files, DNS, mDNS, or other sources. That is why getent can succeed while dig fails, or the reverse.

sh
getent hosts example.com
dig +short example.com
cat /etc/resolv.conf

Records and caching

  • A and AAAA map names to IPv4 and IPv6 addresses
  • CNAME creates an alias to another name
  • MX and TXT serve mail routing and verification
  • TTL controls how long resolvers may cache an answer
  • Search domains let short names expand to fully qualified names

systemd-resolved often manages a stub resolver at 127.0.0.53 and writes a generated resolv.conf. Editing resolv.conf directly may be overwritten, so use resolvectl or the network configuration source.

Use dig to test DNS itself and getent to test the application resolution path. They exercise different layers, so disagreement between them is useful diagnostic information.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why might getent and dig return different results?
  2. 2What is the role of /etc/nsswitch.conf?
  3. 3How does systemd-resolved change resolv.conf management?
  4. 4What does a CNAME record do?

Say it in the interview

Linux name resolution goes through NSS, usually checking /etc/hosts before DNS. Applications call getaddrinfo rather than querying DNS directly. I use getent to test the real resolution path and dig to test DNS itself. Caching and search domains often explain behavior that looks like a DNS failure.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Linux mock interview and get scored feedback on depth, clarity and confidence.