Where the host file lives on your computer
The host file is a plain text document that your operating system checks before it looks up web addresses on the internet. It sits in a specific folder that Windows, Mac, and Linux keep hidden by default — which is why it feels impossible to find. The location changes depending on which system you use, but once you know the path, you can navigate there in under a minute.
Most people never need to touch the host file. System administrators, web developers, and people troubleshooting network problems are the ones who look for it. If you arrived here from a guide that told you to edit your host file, that guide should have also told you where to find it — but this section covers all three operating systems so you have one place to check.
Key Takeaways
- On Windows, the host file is at C:\Windows\System32\drivers\etc\hosts with no file extension.
- On Mac, the host file is at /etc/hosts and you access it through Terminal or a text editor that can open hidden files.
- On Linux, the host file is at /etc/hosts and you can view it with the cat command or edit it with nano or vi.
- You need administrator or root permissions to edit the host file on any system — reading it does not require special access.
Finding the host file on Windows
Open File Explorer and navigate to C:\Windows\System32\drivers\etc. The folder path is real — type it directly into the address bar at the top of File Explorer rather than clicking through folders. When you arrive, look for a file called hosts with no file extension. It will not have a .txt ending even though it is a text file.
If you do not see the hosts file in that folder, your View settings are hiding it. Click the View tab at the top of File Explorer, then check the box next to "Hidden items". The hosts file should appear. If it still does not, the file may have been deleted — you can create a new one, but that is a separate process covered in a guide about editing the host file, not finding it.
Once you see the hosts file, right-click it and choose "Open with" to pick a text editor. Notepad works, but many people prefer a code editor like Visual Studio Code or Notepad++. Do not double-click the file — that may try to open it with the wrong program.
Finding the host file on Mac
The host file on Mac lives at /etc/hosts, but the /etc folder is hidden. The easiest route is to open Terminal (search for it in Spotlight with Command+Space) and type the command cat /etc/hosts. This displays the contents of the file without opening an editor — useful if you just want to read it.
If you need to edit the file, you can open it directly in a text editor. Open Terminal and type nano /etc/hosts. This opens the file in the nano text editor, where you can make changes. When you finish, press Control+X, then Y, then Enter to save. You will be asked for your password because editing the host file requires administrator permission.
Alternatively, you can use Finder to navigate to the file. Press Command+Shift+G to open the "Go to Folder" dialog, then type /etc/hosts and press Enter. This opens the file in your default text editor. Again, you will need your password to save changes.
Finding the host file on Linux
Open a terminal window and type cat /etc/hosts to view the file. This is the fastest way to check what is in your host file without opening an editor. The file is not hidden on Linux — it is in the /etc directory, which is a standard system folder.
To edit the file, type sudo nano /etc/hosts or sudo vi /etc/hosts depending on which text editor you prefer. The sudo command gives you the permissions you need, and you will be prompted for your password. Make your changes, then save and exit the editor. In nano, that is Control+X followed by Y and Enter. In vi, type :wq and press Enter.
If you prefer a graphical editor, you can also open the file with a GUI text editor by typing sudo gedit /etc/hosts (on GNOME desktops) or the equivalent for your desktop environment. The file will open in a window where you can edit it like any other document.
What you will see inside the host file
The host file contains lines that map IP addresses to domain names. Each line has an IP address, then whitespace, then a domain name. For example, a line might read 127.0.0.1 localhost, which tells your computer that the address localhost points to 127.0.0.1 (your own machine). Lines starting with a # are comments and do not do anything.
Most host files come with a few default entries already in place. On Windows, you will see entries for localhost and ::1 (the IPv6 version of localhost). On Mac and Linux, there are usually a few more default entries. These are safe to leave alone. If someone told you to add a line to your host file, that line will be specific to what you are trying to do — a guide about blocking websites, testing a local server, or something similar should tell you exactly what to add.
Permissions and why you might get stuck
On all three systems, you need administrator or root access to edit the host file. You can read it without special permissions, but saving changes requires elevated access. This is intentional — the host file affects how your entire computer connects to the internet, so the operating system protects it from accidental changes.
If you try to edit the file and get a "permission denied" message, you are not running the editor with the right permissions. On Windows, right-click the text editor itself and choose "Run as administrator" before opening the file. On Mac and Linux, use the sudo command in Terminal as shown above. If you are using a graphical editor on Mac, the system will prompt you for your password when you try to save.
Backing up your host file before making changes
Before you edit the host file, make a copy of it in case something goes wrong. On Windows, right-click the hosts file, choose Copy, then right-click in the same folder and choose Paste. Rename the copy to something like hosts.backup. On Mac and Linux, open Terminal and type sudo cp /etc/hosts /etc/hosts.backup. This creates a backup you can restore if your edits cause problems.
If you make changes and your internet stops working or websites stop loading, you can restore the backup. On Windows, delete the broken hosts file and rename the backup back to hosts. On Mac and Linux, type sudo cp /etc/hosts.backup /etc/hosts in Terminal. Restart your browser or flush your DNS cache to see the change take effect.
Frequently Asked Questions
Can I edit the host file with Notepad or TextEdit?
Yes, but you need to be careful about file format. On Windows, Notepad works fine — just open it as administrator first. On Mac, TextEdit will work, but you must change the format from Rich Text to Plain Text before saving, or the file will not work. A dedicated text editor is safer.
What happens if I delete the host file by accident?
Your computer will still work — the host file is not required for normal operation. If you deleted it and made a backup, restore the backup. If not, you can create a new one with just the default localhost entries, or your operating system will recreate a basic version on restart.
Do I need to restart my computer after editing the host file?
Usually not. Most changes take effect when ready. If a website still loads the old version, clear your browser cache or restart your browser. On some systems, flushing the DNS cache speeds things up — on Windows, open Command Prompt as administrator and type ipconfig /flushdns.
Why is the host file hidden on Windows and Mac?
Because it is a system file that most people should never touch. Hiding it prevents accidental changes that could break your internet connection. The file is not truly hidden — it is just marked as a system file, and your operating system hides system files by default to keep the file system less cluttered.
Can I use the host file to block websites?
Yes, by pointing a domain name to a non-routable IP address like 127.0.0.1 or 0.0.0.0. However, this only works on your own computer — it does not block the site for other people on your network. For network-wide blocking, you would need to configure your router or use a DNS service instead.