Linux · Systems fluency
How does DNS resolution work on Linux?
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.
getent hosts example.com
dig +short example.com
cat /etc/resolv.confRecords 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.
Follow-ups you should expect
Interviewers use these to check whether the first answer was understanding or memorisation.
- 1Why might getent and dig return different results?
- 2What is the role of /etc/nsswitch.conf?
- 3How does systemd-resolved change resolv.conf management?
- 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.