Where Is the Hosts File on Linux?
Linux /etc/hosts file with local DNS overrides, adblock lists and dev domains.
Last updated
Linux resolves names through /etc/hosts before DNS, making it the classic spot for dev domains, adblock blocks and outage workarounds. One line maps an IP to hostnames with immediate effect.
Syntax errors here break resolution in confusing ways. Keep a backup before edits and test with getent hosts afterward.
Where Linux stores this, by platform
/etc/hosts
Plain-text IP-to-hostname mappings consulted before DNS per /etc/nsswitch.conf. Localhost entries must stay intact or services binding loopback fail. Back up before editing and verify with getent hosts.
Frequently asked questions
How do I block a domain on Linux?
Point it at 0.0.0.0 in the file above. Large blocklists append thousands of such lines for network-wide ad filtering.
How do I test a site before DNS propagates?
Add its IP and domain to /etc/hosts above. Only your machine resolves it there until real DNS catches up.
Notice an outdated path? Let us know.