Where Is the Hosts File?
The hosts file maps names to IPs at /etc/hosts on Linux and Mac, and System32\drivers\etc\hosts on Windows.
Last updated
The hosts file is the first lookup before DNS. One line maps an IP to names, and the system trusts it over every server. All three desktop OSes keep one in a fixed spot.
Localhost lives here by tradition. Custom entries suit dev domains and quick blocks. It scales to dozens of lines, never to fleet management, which is what DNS servers are for.
Where hosts file stores this, by platform
/etc/hosts
Plain text, one mapping per line. Needs sudo to edit. localhost entries ship by default.
/private/etc/hosts
Same format as Linux. Editing needs admin. Some tools manage it and fight hand edits.
C:\Windows\System32\drivers\etc\hosts
Same format, hidden deep. Needs admin Notepad. Line endings stay CRLF-safe plain text.
Frequently asked questions
How do I block or redirect a domain locally?
Add a line with the IP and name, then flush the DNS cache. Entries override public DNS for that machine only. Remove the line to revert.
How do I share hosts entries across machines?
Run a local resolver or push the file by config management. Each machine reads its own copy, there is no sync built in.
Something rewrote my hosts file. What?
AdAway and similar tools rewrite it. Disable the tool first to restore stock. Leftover entries break resolution after uninstall.
Notice an outdated path? Let us know.