Where Is the Hosts File Located on Windows, Mac, and Linux?
The hosts file is one of the oldest and most quietly powerful files on any computer. It sits in a specific folder on your operating system, and knowing where to find it — and what it actually does — can save you real troubleshooting time.
What Is the Hosts File?
Before locating it, it helps to understand what it does. The hosts file is a plain text file that maps hostnames to IP addresses. When you type a web address into your browser, your computer checks this file before reaching out to a DNS (Domain Name System) server.
Think of DNS as a phone book for the internet — it translates human-readable addresses like example.com into numerical IP addresses computers actually use. The hosts file is a local override of that phone book. Whatever you write in it takes priority.
Common uses include:
- Blocking websites by redirecting them to a non-existent address
- Testing local development environments before a site goes live
- Bypassing DNS propagation delays when a domain's IP has recently changed
- Filtering ads or malicious domains at the system level
Where Is the Hosts File on Windows? 🖥️
On Windows, the hosts file lives here:
C:WindowsSystem32driversetchosts The file has no extension — it's simply named hosts. You won't find a .txt on the end.
To open and edit it, you need to run your text editor (like Notepad) as Administrator. Without elevated permissions, Windows won't let you save changes to the file, even if you can open it.
Quick steps:
- Press
Windows + Sand search for Notepad - Right-click Notepad and choose Run as administrator
- Use File → Open and navigate to the path above
- Change the file type filter to All Files so the hosts file appears
One thing to be aware of: the path is consistent across Windows 7, 8, 10, and 11. The folder structure hasn't changed.
Where Is the Hosts File on macOS?
On macOS, the hosts file is located at:
/etc/hosts This path follows Unix conventions, which makes sense — macOS is built on a Unix foundation. The /etc directory stores system-wide configuration files, and hosts is one of them.
To edit it, you'll need to use the Terminal and a command-line text editor, since it's a protected system file.
sudo nano /etc/hosts The sudo prefix gives you temporary administrator-level access. You'll be prompted for your Mac's login password. After editing, save with Ctrl + O and exit with Ctrl + X.
This path is consistent across macOS versions going back many years, including modern versions like Ventura, Sonoma, and Monterey.
Where Is the Hosts File on Linux?
On Linux, the location matches macOS exactly:
/etc/hosts Since both systems share Unix roots, this is no coincidence. The /etc/hosts file is a standard part of the Linux Filesystem Hierarchy Standard (FHS).
The editing process is the same:
sudo nano /etc/hosts Replace nano with your preferred editor — vim, gedit, or any other text editor you're comfortable with.
The key variable on Linux is your distribution and desktop environment. On some distros with graphical file managers (like Ubuntu with Nautilus), you may be able to navigate to the file visually, but you'll still need root permissions to edit it.
Hosts File Locations at a Glance
| Operating System | Hosts File Path |
|---|---|
| Windows 10 / 11 | C:WindowsSystem32driversetchosts |
| Windows 7 / 8 | C:WindowsSystem32driversetchosts |
| macOS (all modern versions) | /etc/hosts |
| Linux (most distributions) | /etc/hosts |
| Android (rooted) | /etc/hosts |
| iOS (jailbroken) | /etc/hosts |
What the File Actually Looks Like
The hosts file is plain text with a straightforward structure:
127.0.0.1 localhost ::1 localhost 0.0.0.0 blockeddomain.com Each line pairs an IP address on the left with one or more hostnames on the right. Lines beginning with # are comments and are ignored by the system.
Redirecting a domain to 0.0.0.0 or 127.0.0.1 effectively blocks it — the request goes nowhere useful.
Variables That Change Your Experience 🔧
Finding the file is the easy part. What happens next depends on several factors:
Permissions and user account type — On all three platforms, editing requires administrator or root access. Standard user accounts can't save changes, which is a deliberate security measure.
Security software — Some antivirus programs and endpoint security tools monitor the hosts file for unauthorized changes. Edits you make might trigger a warning, be rolled back automatically, or require you to whitelist your own changes.
DNS caching — Even after editing the hosts file, your browser or OS may have cached the old DNS resolution. You may need to flush the DNS cache before changes take effect. On Windows, that's ipconfig /flushdns in Command Prompt. On macOS, the command varies slightly by version.
Number of entries — Very large hosts files (some ad-blocking lists contain tens of thousands of entries) can introduce a small but measurable delay in domain lookups, depending on your hardware and OS.
Mobile and locked-down environments — On standard (non-rooted, non-jailbroken) Android and iOS devices, the hosts file is not accessible. This changes what's possible entirely for users on mobile-first setups.
Whether modifying the hosts file makes sense for your situation — blocking ads, testing a dev environment, or something else — comes down to what you're actually trying to accomplish and how your system is configured.