What is the purpose of /etc/hosts and how does DNS resolution work in Linux?
DNS resolution order in Linux (configured in /etc/nsswitch.conf):
- /etc/hosts: Local overrides. Checked first. Maps hostnames to IPs without DNS lookup.
- DNS servers (
/etc/resolv.conf): The configured nameservers are queried via UDP port 53.
Common use cases for /etc/hosts: local development overrides, blocking domains by pointing to 127.0.0.1, testing service connectivity using a service name before DNS is configured. In containers, Kubernetes manages /etc/hosts via its own CoreDNS system.