Where Do You Find the Hosts File on Windows, Mac, and Linux?

The hosts file is one of the oldest and most quietly powerful files on any computer. It sits in your operating system, doing its job without fanfare — and most people never think about it until they need to block a website, troubleshoot DNS issues, or test a server before it goes live. Finding it, however, isn't always obvious. Its location varies by operating system, and on modern systems it's tucked away in protected directories by design.

What Is the Hosts File and What Does It Do?

Before finding it, it helps to understand what you're looking for. The hosts file is a plain text file that maps hostnames (like example.com) to IP addresses (like 93.184.216.34). When you type a web address into your browser, your computer checks the hosts file before it queries a DNS server. If there's a matching entry, that IP address is used immediately — no DNS lookup required.

This makes the hosts file useful for:

  • Blocking websites by redirecting their domain to 0.0.0.0 or 127.0.0.1
  • Testing local development environments before DNS propagates
  • Overriding DNS for a specific domain on a single machine
  • Troubleshooting network issues related to name resolution

It's a local file with system-level authority. Changes take effect almost immediately, and no third-party tools are required to use it.

Hosts File Location by Operating System 🗂️

The path differs depending on which OS you're running.

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

On Windows, the file has no extension — it's literally named hosts, not hosts.txt. Many text editors will try to add .txt if you're not careful when saving edits.

On macOS and Linux, /etc/hosts is standard across virtually all distributions and versions. The /etc directory is a system configuration folder, and the hosts file lives there alongside other core system settings.

How to Navigate to the Hosts File

On Windows

The most reliable method is opening a text editor as Administrator and navigating to the path manually:

  1. Search for Notepad in the Start menu
  2. Right-click and select Run as administrator
  3. Use File > Open, then navigate to C:WindowsSystem32driversetc
  4. Change the file filter from "Text Documents" to All Files — otherwise the hosts file won't appear
  5. Select hosts and open it

Alternatively, you can press Win + R, type notepad C:WindowsSystem32driversetchosts, and run it as administrator.

On macOS

The hosts file on Mac requires Terminal to edit directly, though you can navigate to it in Finder using Go > Go to Folder and typing /etc/hosts. To edit it, most users use:

sudo nano /etc/hosts 

This opens the file in the nano text editor with root-level permissions. After saving, it's good practice to flush the DNS cache with sudo dscacheutil -flushcache.

On Linux

The process is nearly identical to macOS. Open a terminal and use:

sudo nano /etc/hosts 

Or substitute your preferred editor — vim, gedit, kate, etc. The file itself is the same structure regardless of distribution.

What You'll See Inside the Hosts File

A default hosts file is mostly comments (lines starting with #) and a few basic entries:

127.0.0.1 localhost ::1 localhost 

The 127.0.0.1 is the loopback address — it points back to your own machine. The ::1 is the IPv6 equivalent. Any entries you add follow the same format: IP address, then one or more spaces or a tab, then the hostname.

Why You Need Administrator Access

The hosts file is protected by the operating system because changes to it directly affect how your machine resolves domain names. A malicious program that silently edits the hosts file could redirect you from a legitimate banking site to a fraudulent copy — an attack known as hosts file poisoning. Because of this, Windows, macOS, and Linux all require elevated permissions to modify it.

On Windows, this means running your editor as Administrator. On macOS and Linux, it means using sudo. Trying to save changes without the right permissions will either fail silently or produce an access denied error.

Variables That Affect Your Experience ⚙️

Finding and editing the hosts file isn't equally straightforward for everyone. A few factors shape how the process goes:

  • OS version: Paths are consistent within each OS family, but security layers (like Windows UAC or macOS System Integrity Protection) behave differently across versions
  • Security software: Some antivirus and endpoint security tools actively monitor or lock the hosts file and may alert or block changes
  • Technical comfort level: Command-line editing on macOS/Linux is second nature for developers but unfamiliar territory for general users
  • Purpose of the edit: Blocking a single site is simple; setting up a complex local development environment introduces more variables around DNS flushing and browser caching

The hosts file also doesn't work the same way across all applications. Some software — including certain browsers and apps — maintains its own DNS cache or bypasses the system hosts file entirely. Whether your changes have the intended effect depends on what you're trying to accomplish and what software is involved.

What the right approach looks like for your situation depends on which OS you're running, what you're trying to achieve, and how your system's security settings are configured.