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 predates the modern DNS system and still works today — silently influencing how your machine resolves domain names before any external server gets involved. Knowing where it lives, and what it does, gives you meaningful control over your own network behavior.

What the Hosts File Actually Does

Every time you type a web address into a browser, your computer needs to translate that human-readable name (like example.com) into a numerical IP address. Normally, that job goes to a DNS (Domain Name System) server — usually one provided by your ISP or a third-party service like Google or Cloudflare.

But before your system even contacts a DNS server, it checks the hosts file. If that file contains a matching entry for the domain you're requesting, your computer uses that IP address directly — no DNS query needed. This makes the hosts file a local override mechanism. It's used for:

  • Blocking websites by redirecting domains to a non-routable address (commonly 0.0.0.0 or 127.0.0.1)
  • Testing web development environments by pointing a domain to a local server
  • Overriding DNS for specific domains without changing global DNS settings
  • Speeding up lookups for frequently accessed internal resources

Hosts File Location by Operating System 🗂️

The file path differs depending on your OS. Here's where to find it on the most common systems:

Operating SystemHosts File Path
Windows 10 / 11C:WindowsSystem32driversetchosts
Windows 7 / 8C:WindowsSystem32driversetchosts
macOS (all modern versions)/etc/hosts
Ubuntu / Debian Linux/etc/hosts
Fedora / RHEL Linux/etc/hosts
Android (rooted)/system/etc/hosts
iOS (jailbroken)/etc/hosts

On Windows, the etc folder is hidden within the system driver structure and won't show up in a standard file browser search unless you navigate to it directly. On macOS and Linux, /etc/hosts follows the Unix convention — /etc is a standard directory for system-wide configuration files.

How to Open and Edit the Hosts File

The hosts file is a plain text file, but editing it requires elevated permissions on every major OS.

On Windows

You can't simply double-click and save changes. You need to open your text editor (Notepad, VS Code, etc.) as Administrator:

  1. Search for Notepad in the Start menu
  2. Right-click and select Run as administrator
  3. Use File > Open and navigate to C:WindowsSystem32driversetc
  4. Change the file filter from .txt to All Files to see the hosts file
  5. Open, edit, and save

On macOS and Linux

Editing requires using the Terminal with elevated privileges. The standard command is:

sudo nano /etc/hosts 

You'll be prompted for your admin password. Once inside, you can add or modify entries, then save with Ctrl+O and exit with Ctrl+X.

What the Hosts File Format Looks Like

Each entry in the hosts file follows a simple pattern:

IP_address hostname [optional alias] 

For example:

127.0.0.1 localhost 0.0.0.0 ads.example.com 192.168.1.10 devserver.local 

Lines beginning with # are comments and are ignored by the system. The default hosts file on most operating systems includes a few standard entries (like mapping localhost to 127.0.0.1) and a set of comments explaining the format.

Variables That Affect How the Hosts File Behaves

The hosts file itself is simple, but several factors determine how much it matters in your specific setup:

Browser and application behavior — Most browsers respect the system hosts file, but some configurations, particularly those using DNS over HTTPS (DoH), may bypass local DNS resolution entirely. Chrome, Firefox, and Edge all have DoH settings that, when enabled, can route DNS queries directly to a remote encrypted resolver — potentially ignoring hosts file entries.

Operating system version — The file location has remained consistent across Windows, macOS, and Linux for many years, but the permissions model and how quickly changes take effect can vary. On Windows, a DNS cache flush (ipconfig /flushdns) is sometimes needed before new entries apply.

Security software — Some antivirus and endpoint security tools monitor the hosts file for unauthorized changes (a known malware tactic) and may block edits or restore the file to a previous state.

Mobile and managed devices — On Android, the hosts file is only accessible on rooted devices. On iOS, it requires jailbreaking. On company-managed or MDM-enrolled devices, group policies may restrict or override local hosts file changes entirely.

Network configuration — In environments using split-DNS, VPNs, or corporate proxy setups, the hosts file may be overridden downstream depending on how DNS resolution is prioritized.

🔍 The Spectrum of Use Cases

Someone blocking ads on a home computer has a very different relationship with the hosts file than a developer mapping a staging domain to a local environment, or a sysadmin managing custom name resolution across a fleet of machines. The same file, the same location — but the context around editing it, the risk of getting it wrong, and the tools used to manage it differ significantly.

A simple typo in the hosts file can make a domain entirely unreachable on that machine. For personal use, that's recoverable. In production or managed environments, the consequences scale with the setup.

What you can do with the hosts file — and how safely — depends heavily on your OS, your technical access level, whether your applications respect local DNS, and what you're actually trying to accomplish.