The host file lives in a specific system folder that Windows, Mac, and Linux keep hidden by default

The host file is a plain text document your operating system checks before it looks up a website address on the internet. It sits in a protected system folder, not in your Documents or Downloads. Where it lives depends on which operating system you use, and you will need to show hidden files to see it — most people never notice it exists because the system keeps it out of sight.

You might need to find or edit your host file if you are troubleshooting a website that will not load, testing a website before it goes live, or blocking access to a site on your own computer. Understanding where it is and how to access it safely is part of managing your own digital environment.

Key Takeaways

  • On Windows, the host file is at C:\Windows\System32\drivers\etc\hosts with no file extension.
  • On Mac and Linux, it is at /etc/hosts and you will need administrator permission to edit it.
  • You must show hidden files and folders in your operating system before you can see the etc folder.
  • The host file is a plain text document — open it with Notepad (Windows) or a text editor, never with Word or another formatting program.
  • Editing the host file incorrectly can break your internet connection, so back up the original before you make changes.

Finding the host file on Windows

On Windows 10 and Windows 11, the host file is located at C:\Windows\System32\drivers\etc\hosts. The file has no extension — it is not hosts.txt, just hosts. The folder it sits in (etc) is hidden by default, so you will not see it when you open File Explorer and navigate to that path.

To see hidden files and folders in Windows, open File Explorer and go to the View tab at the top. Click the checkbox next to "Hidden items" — this will show all the hidden folders on your computer. Now navigate to C:\Windows\System32\drivers\ and you will see the etc folder. Open it and the hosts file is inside.

Once you have found it, right-click the hosts file and choose "Open with" then select Notepad. Do not use Word, Google Docs, or any other word processor — these add formatting that will break the file. If you plan to edit it, you will need to run Notepad as administrator: right-click Notepad in your Start menu and choose "Run as administrator" before opening the file.

Finding the host file on Mac

On Mac, the host file is at /etc/hosts. The path starts with a forward slash, which means it is at the root of your hard drive. The etc folder is hidden, so you will not see it in Finder by default.

The easiest way to reach it is through the Terminal process. Open Terminal (you can find it in Applications > Utilities or search for it with Spotlight). Type the command sudo nano /etc/hosts and press Enter. You will be asked for your administrator password. Type it in — the cursor will not move as you type, which is normal — and press Enter again. The host file will open in the nano text editor right in Terminal.

If you prefer to use a graphical text editor instead of Terminal, you can open Finder, press Command+Shift+Period to show hidden files, then navigate to /etc/ and find the hosts file. Right-click it and choose "Open With" and select a text editor like TextEdit (set it to plain text format, not rich text). You will need to enter your administrator password to save any changes.

Finding the host file on Linux

On Linux, the host file is at /etc/hosts, the same path as Mac. Most Linux distributions do not hide system files the way Windows and Mac do, so you may be able to see it directly if you open a file manager and navigate to the /etc/ folder.

The command-line approach is usually faster: open a terminal and type sudo nano /etc/hosts or sudo gedit /etc/hosts depending on which text editor you prefer. You will be prompted for your administrator password. Once the file opens, you can view or edit it as needed.

What the host file contains and why it matters

The host file is a straightforward list of IP addresses matched to domain names. Each line has an IP address, then spaces or tabs, then a website address. For example, a line might read 127.0.0.1 localhost, which tells your computer that the address "localhost" points to your own machine.

When you type a website address into your browser, your computer checks the host file first before asking the internet's DNS servers where that address lives. If the host file has an entry for that address, your computer uses that entry instead of looking it up online. This is why people use the host file to block websites (by pointing them to a dead address) or to test a website on their own computer before it goes live on the real internet.

The host file usually contains only a few default entries. If you see many entries you did not add, or entries for websites you do not recognize, this can be a sign that malware has modified your host file. In that case, you should restore it from a backup or consult a security professional.

How to safely edit the host file

Before you make any changes to the host file, create a backup. On Windows, copy the hosts file to your Desktop or Documents folder. On Mac or Linux, you can use Terminal to make a copy: type sudo cp /etc/hosts /etc/hosts.backup and press Enter. This way, if something goes wrong, you can restore the original.

When you edit the file, remember that each line must follow the format: IP address, then at least one space or tab, then the domain name. Do not add extra spaces at the end of lines or leave blank lines in the middle of entries. Save the file as plain text with no formatting. On Windows, make sure Notepad is not adding a .txt extension when you save — the file must be named exactly hosts with no extension.

After you save changes, you may need to flush your DNS cache before the changes take effect. On Windows, open Command Prompt as administrator and type ipconfig /flushdns. On Mac, open Terminal and type sudo dscacheutil -flushcache. On Linux, the command varies by distribution, but sudo systemctl restart systemd-resolved works on most modern systems.

Common problems when editing the host file

The most common mistake is opening the host file in a word processor like Microsoft Word or Google Docs. These programs add invisible formatting characters that break the file. Always use a plain text editor: Notepad on Windows, TextEdit (in plain text mode) or nano on Mac, or nano or gedit on Linux.

Another frequent problem is accidentally adding a .txt extension when you save. On Windows, Notepad will sometimes do this automatically. To prevent it, when you save the file, put the filename in quotes: "hosts" instead of hosts. This tells Notepad not to add an extension.

If you edit the host file and your internet stops working or a website you need becomes unreachable, restore your backup when ready. On Windows, copy the backup file back to C:\Windows\System32\drivers\etc\ and rename it to hosts. On Mac or Linux, type sudo cp /etc/hosts.backup /etc/hosts in Terminal. Then flush your DNS cache as described above.

Frequently Asked Questions

Can I edit the host file without administrator permission?

No. The host file is a system file, and your operating system protects it to prevent accidental or malicious changes. You must run your text editor as administrator (Windows) or use sudo (Mac and Linux) to save any edits. If you try to save without the right permissions, the file will not change.

What should I do if I cannot find the etc folder?

Make sure you have enabled hidden files in your operating system. On Windows, go to View in File Explorer and check "Hidden items". On Mac, press Command+Shift+Period in Finder. On Linux, most file managers have a View menu option to show hidden files. If you still cannot find it, use the command-line method instead — Terminal will take you directly to the file.

Is it safe to edit the host file myself?

Yes, if you follow the rules: use a plain text editor only, back up the original first, and be careful with the format. The host file is just a text document, and you can always restore it from your backup if something goes wrong. However, if you are not sure what you are doing, it is safer to leave it alone — an incorrect entry can break your internet connection.

Why does my antivirus warn me about the host file?

Some antivirus programs flag the host file because malware sometimes modifies it to redirect you to fake websites. If your antivirus warns you, check the file yourself: open it and look for entries you did not add. If you see unfamiliar website addresses, restore your backup and run a full antivirus scan. If the file looks normal, you can usually tell your antivirus to ignore it.

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

No. Restarting is not necessary. You only need to flush your DNS cache, which takes a few seconds. After you flush the cache, the changes take effect when ready and you can test them in your browser.