The host file location depends on your operating system

The host file is a plain text file your computer checks before looking up web addresses on the internet. It sits on your hard drive in a specific folder that differs by operating system. On Windows, it lives in C:\Windows\System32\drivers\etc\. On Mac and Linux, you'll find it at /etc/hosts. The file itself is always named hosts with no file extension.

You need administrator or root access to view and edit this file. Most people never touch it, but system administrators and advanced users modify it to block websites, redirect traffic, or test local websites before they go live. If you're looking for it because you suspect malware has altered it, or because you need to make a specific network change, knowing the exact path saves time.

Key Takeaways

  • On Windows, the host file is located at C:\Windows\System32\drivers\etc\hosts with no file extension.
  • On Mac and Linux, the host file is at /etc/hosts and can be opened from the terminal or a text editor.
  • You must have administrator or root permissions to edit the host file; opening it as a regular user will only let you read it.
  • The host file is a plain text file that maps domain names to IP addresses, and changes take effect immediately without restarting.

Finding the host file on Windows

On Windows 10, 11, or earlier versions, open File Explorer and navigate to C:\Windows\System32\drivers\etc\. The folder path is the same regardless of Windows version. You may not see the hosts file at first because Windows hides files without extensions by default. To show all files, click the View tab at the top of File Explorer, then check the box labeled "File name extensions" or "Hidden items" depending on your Windows version.

Once you see the hosts file, right-click it and select "Open with" to choose a text editor. Notepad works fine. If you try to save changes and Windows blocks you, close the file, right-click it again, select Properties, and uncheck "Read-only" at the bottom of the window. Then open it again with Notepad and try editing. Some users find it easier to open Notepad first, then use File > Open and navigate to the hosts file from within the editor.

Finding the host file on Mac

On Mac, the host file lives at /etc/hosts, but it's not visible in Finder by default because it's in a hidden system folder. The easiest way to access it is through Terminal. Open Terminal (search for it in Spotlight or find it in Applications > Utilities), then type sudo nano /etc/hosts and press Enter. You'll be prompted for your password. Type it in — you won't see the characters appear, but that's normal — and press Enter again.

The nano text editor will open with the host file displayed. Make your changes, then press Control + X to exit. Nano will ask if you want to save; type Y for yes and press Enter. If you prefer a graphical editor instead of Terminal, you can open Finder, press Command + Shift + G, paste /etc/hosts into the box, and click Go. Then right-click the file and open it with TextEdit or another text editor. Remember that you'll need to save it as plain text, not rich text, for the changes to work.

Finding the host file on Linux

On Linux distributions like Ubuntu, Debian, or Fedora, the host file is at /etc/hosts, the same location as on Mac. Open a terminal and use the command sudo nano /etc/hosts or sudo vim /etc/hosts depending on which text editor you prefer. Enter your password when prompted. If you're not comfortable with command-line editors, you can also open the file with a graphical text editor by running sudo gedit /etc/hosts (on GNOME desktops) or sudo kate /etc/hosts (on KDE desktops).

After you make changes and save the file, the changes take effect immediately on most Linux systems. You don't need to restart your computer or any services. If DNS lookups still seem cached, you can flush the DNS cache by running sudo systemctl restart systemd-resolved on systems using systemd, though this is rarely necessary for host file changes.

What the host file contains and how to read it

The host file is a simple list of IP addresses and domain names separated by whitespace. Each line maps one IP address to one or more domain names. For example, a line might read 127.0.0.1 localhost, which tells your computer that the address "localhost" points to your own machine. Another line might be 192.168.1.100 myserver.local, which redirects traffic for "myserver.local" to a specific IP on your local network.

Lines starting with a hash symbol (#) are comments and don't do anything. Most host files come with several commented-out examples at the top. When you add a new entry, put the IP address first, then one or more spaces or tabs, then the domain name. If you want one IP to answer to multiple names, list them all on the same line separated by spaces: 192.168.1.50 server1.local server1 backup.local. Save the file and your computer will use these mappings the next time it tries to reach those addresses.

Why you might need to edit the host file

System administrators edit the host file to test websites on a development server before the domain name points to the live server. By adding a line like 192.168.1.10 example.com, you can visit example.com in your browser and see the development version instead of the live site. This lets you check how the site looks and functions before going public.

Some people also use the host file to block ads or malicious websites by pointing them to 127.0.0.1 (your own computer), which prevents your browser from reaching them. Security researchers sometimes find that malware has altered the host file to redirect traffic to phishing sites or fake versions of legitimate services. If you suspect this has happened, checking your host file is one of the first troubleshooting steps. You can compare your file to a clean copy from a trusted source or look for entries you don't recognize.

Frequently Asked Questions

Do I need to restart my computer after editing the host file?

No. Changes to the host file take effect immediately on all operating systems. Your browser may cache old DNS lookups, so if a redirect doesn't work right away, try clearing your browser cache or opening the site in a private window. On rare occasions, flushing your system's DNS cache (a command-line operation) helps, but it's usually not necessary.

What if I can't save changes to the host file?

You're likely missing administrator or root permissions. On Windows, right-click Notepad itself and select "Run as administrator" before opening the file. On Mac and Linux, use the sudo command in Terminal. If you're still blocked, the file may be marked read-only; check the file's properties and uncheck the read-only box.

Can malware hide entries in the host file?

Yes. Malware sometimes modifies the host file to redirect you to fake versions of banking sites or search engines. If you suspect infection, open the host file and look for entries you don't recognize. Compare it to a clean host file from another computer or a trusted backup. Removing suspicious entries usually stops the redirection, but a full malware scan is still recommended.

Is the host file the same on all versions of Windows?

The location and function are the same on Windows 7, 8, 10, and 11. The path C:\Windows\System32\drivers\etc\hosts is consistent. The main difference is how you show hidden files in File Explorer, which varies slightly between versions, but the file itself hasn't changed.