DNS & Name Resolution

Name Resolution

FilePurpose
/etc/hostsStatic hostname → IP mappings (checked first)
/etc/resolv.confDNS server(s) (nameserver)
/etc/nsswitch.confResolution order (hosts: files dns)
CommandPurpose
dig example.comFull DNS query
dig +short A example.comJust the answer
host example.comSimple lookup
nslookup example.comInteractive lookup
getent hosts example.comResolve via nsswitch
$ dig +short github.com
140.82.112.3
Exam tip: /etc/hosts is consulted before DNS (per nsswitch.conf), so a wrong entry there overrides real DNS.