What it is
The hosts file is a plain-text list of hostname to IP address mappings maintained on each machine. Before (or alongside, depending on resolver configuration) querying DNS, many stacks consult hosts for static answers—making it a simple way to override DNS for testing, blocklists, or legacy fixed mappings.
Where it lives
| OS | Path | Edit notes |
|---|---|---|
| Windows | %SystemRoot%\System32\drivers\etc\hosts | Requires elevation for standard editors; mind 64-bit editor redirection on WOW64 |
| Linux / macOS | /etc/hosts | Root-owned; use sudo with care |
Line format
Each non-comment line is typically IP-address hostname [aliases…]. Lines starting with # are comments. Multiple names can share one IP; duplicate conflicting lines create confusion—keep one authoritative mapping per hostname you care about.
Resolver interaction
On Windows, the DNS Client service uses hosts together with cached lookups and configured DNS servers. Applications that implement DNS-over-HTTPS or their own resolver may bypass hosts, which surprises testers who expect a global override. After edits, ipconfig /flushdns clears the client cache but does not change remote resolver behavior.
Security and hygiene
Malware often hijacks hosts to redirect banking sites. Enterprise agents sometimes monitor the file. Prefer temporary entries for dev testing, document changes in tickets, and remove stale overrides to avoid “works on my machine” DNS ghosts.
Related: How DNS works, Flush DNS cache, What is an FQDN, Windows ipconfig explained.