The host file location depends on your operating system
The host file is a text file on your computer that tells your system which websites go to which addresses, before it even asks the internet. It sits in a specific folder that Windows, Mac, and Linux each keep in different places. You need to know where yours is if you want to block a website, test a site before it goes live, or troubleshoot connection problems.
On Windows, the host file lives at C:\Windows\System32\drivers\etc\hosts — no file extension, just "hosts". On Mac, it is at /etc/hosts. On Linux, it is also at /etc/hosts. The file has no extension on any system, and it is plain text, so you open it with Notepad (Windows) or TextEdit (Mac) rather than Word.
Key Takeaways
- Windows stores the host file at C:\Windows\System32\drivers\etc\hosts; Mac and Linux store it at /etc/hosts.
- You need administrator or root access to edit the file — opening it as a regular user will not let you save changes.
- Open the file with Notepad on Windows or TextEdit on Mac, never with Word or another formatted editor.
- Each line in the host file pairs an IP address with a domain name, and changes take effect when ready without restarting.
How to open the host file on Windows
Right-click Notepad and choose "Run as administrator" — this is the critical step most people miss. If you open Notepad normally and then try to open the host file, you will be able to read it but not save any changes. Once Notepad is open as administrator, go to File > Open and navigate to C:\Windows\System32\drivers\etc\. The folder path will not show the file at first because Notepad is set to look for .txt files by default. Change the dropdown at the bottom right from "Text Documents (.txt)" to "All Files (*.*)" and the hosts file will appear.
If you cannot find the etc folder, make sure you are typing the full path correctly: start from the C: drive, then Windows, then System32, then drivers, then etc. Do not try to navigate by clicking through folders if you are not used to it — using the address bar is faster and more reliable.
How to open the host file on Mac
Open Terminal (search for it in Spotlight or find it in Applications > Utilities). Type sudo nano /etc/hosts and press Enter. You will be asked for your password — type it in and press Enter again. The file will open in the nano text editor, which runs inside Terminal. To edit, just start typing. When you are done, press Control + X, then Y, then Enter to save and exit.
If you prefer not to use Terminal, you can also open TextEdit, go to Format menu and change it to "Plain Text", then use File > Open and press Command + Shift + G to type the path /etc/hosts directly. You will need to enter your password when you try to save. Either method works — Terminal is faster once you are used to it, but TextEdit is more familiar if you rarely use the command line.
How to open the host file on Linux
Open a terminal window and type sudo nano /etc/hosts, then enter your password. The file opens in nano, the same text editor as on Mac. Make your changes, then press Control + X, Y, and Enter to save. If you use a different Linux distribution with a graphical interface, you can also open a file manager, navigate to the root directory, then the etc folder, find the hosts file, right-click it, and open it with a text editor — but you will need to run the editor as root or sudo to save changes.
Some Linux systems use vi or vim instead of nano. If you see a different interface, press Escape, type :q! and press Enter to exit without saving, then try the nano command instead.
What the host file looks like and how to edit it
When you open the file, you will see lines that look like this: 127.0.0.1 localhost and ::1 localhost. These are already there and should not be changed. Each line has an IP address on the left, then one or more spaces, then a domain name on the right. To block a website or redirect it to a different address, you add a new line with the IP address you want and the domain name you want to send there.
For example, if you type 127.0.0.1 example.com on a new line, your computer will treat example.com as if it points to your own machine (127.0.0.1 is always your local computer). This is useful for testing a website before it goes live, or for blocking a site so it will not load. If you want to block a site, use 127.0.0.1 or 0.0.0.0 — both work, though 0.0.0.0 is slightly more efficient. Changes take effect when ready; you do not need to restart your computer.
Why you might need to edit the host file
The most common reason is to test a website on your own computer before the domain name points to the live server. If you are a web developer or designer, you can add a line that sends a domain to your local testing environment, so you can see how the site will look without publishing it yet. Another reason is to block a website — adding a line that sends it to 127.0.0.1 or 0.0.0.0 will prevent it from loading on your computer.
Some people also use the host file to speed up browsing by caching frequently visited sites, though this is less common now that browsers do this automatically. If you are troubleshooting a connection problem, your IT support person might ask you to check or edit the host file to rule out a local redirect. In all cases, remember that changes only affect your own computer — they do not change anything for other users or devices on your network.
Common mistakes and how to avoid them
The biggest mistake is forgetting to run your editor as administrator (Windows) or with sudo (Mac and Linux). If you edit the file and the changes do not save, this is almost always why. The second mistake is using a formatted editor like Word instead of plain text — Word adds invisible formatting that breaks the host file. Always use Notepad, TextEdit in Plain Text mode, or nano.
A third mistake is getting the IP address or domain name wrong. Double-check that you have typed both correctly, with no extra spaces at the end of the line. If you add a line and it does not work, open the file again and look for typos. If you want to undo a change, you can straightforward delete the line you added — the original entries should stay as they are. If you accidentally delete something you did not mean to, close without saving and open the file again to start over.
Frequently Asked Questions
Can I see the host file in Windows File Explorer?
Yes, but you have to navigate to it manually. Go to C:\Windows\System32\drivers\etc\ and look for a file called "hosts" with no extension. If you do not see it, make sure "Show hidden files" is turned on in View options. You can also type the full path directly into the address bar at the top of File Explorer.
What happens if I delete the host file by accident?
Your computer will still work — the host file is not required to run. However, some programs may behave oddly. You can restore it by copying a fresh one from another computer with the same operating system, or by reinstalling your OS. For most people, it is easier to just leave it alone unless you have a specific reason to edit it.
Do I need to restart my computer after editing the host file?
No. Changes take effect when ready. If a website still does not load the way you expect after editing the file, try clearing your browser cache or opening the site in a different browser, because your browser may be remembering the old address.
Can I edit the host file on my phone or tablet?
Not easily. Phones and tablets do not give you access to system files the way computers do. If you need to block a website on a phone, use parental controls or a browser extension instead.
What if I want to block multiple websites?
Add one line for each domain. For example, you can add 127.0.0.1 site1.com on one line and 127.0.0.1 site2.com on the next line. You can add as many as you want, and they all take effect at once.