What is the purpose of /etc/hosts and how does DNS resolution work in Linux?

Easy Topic: Linux May 24, 2026

DNS resolution order in Linux (configured in /etc/nsswitch.conf):

  1. /etc/hosts: Local overrides. Checked first. Maps hostnames to IPs without DNS lookup.
  2. 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.

← Previous How do you use awk, sed, and grep... Next → What is a Load Average in Linux and...

Practice Similar Questions

Back to Linux Topics