What the host file is and where it lives
The host file is a text document on your computer that tells your system which websites to load when you type a web address into your browser. Instead of asking the internet to look up a domain name, your computer checks this file first. If the address is listed there, it goes to whatever location the file specifies — which might be a website, a local folder, or nowhere at all.
The host file sits in a specific system folder that Windows, Mac, and Linux all keep hidden by default. You cannot find it by browsing your Documents or Desktop. You have to navigate to the system folder directly, and the path is different depending on which operating system you use.
Most people never need to touch the host file. But if you are troubleshooting a website that will not load, testing a website before it goes live, or blocking a site from opening, you will need to know where it is and how to open it.
Key Takeaways
- The host file is located in a hidden system folder: C:\Windows\System32\drivers\etc\hosts on Windows and /etc/hosts on Mac and Linux.
- You must open the host file with a text editor like Notepad, not with Word or another document program.
- Editing the host file requires administrator or root access, and changes take effect immediately without restarting.
- A single typo in the host file can break website access, so back up the original before making changes.
Finding the host file on Windows
On Windows, the host file lives inside the system folder where Windows stores its core files. The full path is C:\Windows\System32\drivers\etc\hosts. You cannot see this folder by opening File Explorer and clicking through folders — the etc folder is hidden by default.
The fastest way is to use the Run dialog. Press Windows key + R on your keyboard. A small box will appear. Type this exactly: notepad C:\Windows\System32\drivers\etc\hosts and press Enter. Notepad will open with the host file loaded inside it. If a dialog box asks whether you want to create a new file, click No — the file already exists.
If that does not work, you may need administrator access. Close Notepad, right-click on Notepad itself (not a file), and select Run as administrator. Then use the Run dialog again with the same command.
An alternative route: open File Explorer, paste this into the address bar at the top: C:\Windows\System32\drivers\etc and press Enter. You will see a file called hosts with no file extension. Right-click it, select Open with, and choose Notepad.
Finding the host file on Mac
On Mac, the host file is at /etc/hosts in the root of your hard drive. Like Windows, this folder is hidden. The easiest method is to use the Terminal application, which lets you open files directly by typing their path.
Open Terminal (search for it in Spotlight by pressing Command + Space, type Terminal, and press Enter). At the prompt, type: sudo nano /etc/hosts and press Enter. You will be asked for your password — type it (the characters will not show on screen) and press Enter again. The host file will open in the nano text editor.
If you prefer a graphical approach, open Finder, press Command + Shift + G (Go to Folder), type /etc/hosts, and press Enter. The file will appear. Right-click it and select Open With, then choose TextEdit. Before you save any changes, go to Format menu and select Make Plain Text — TextEdit defaults to rich text, which will corrupt the file.
Finding the host file on Linux
On Linux, the host file is at /etc/hosts, the same location as Mac. Open a terminal window and type: sudo nano /etc/hosts and press Enter. Enter your password when prompted. The file will open in nano, a simple text editor built into most Linux systems.
If you prefer a graphical text editor, you can use gedit, Kate, or another editor your system has installed. The command would be: sudo gedit /etc/hosts (or replace gedit with your editor name). Either way, you need the sudo command because the host file requires root access to edit.
What you will see when you open it
When the host file opens, you will see lines that look like this: 127.0.0.1 localhost and possibly ::1 localhost. These are default entries that tell your computer how to find itself. Below that, you may see nothing, or you may see other entries if someone has edited the file before.
Each line follows the same pattern: an IP address, then one or more spaces or tabs, then a domain name. For example: 192.168.1.100 mywebsite.local tells your computer that when you type mywebsite.local into your browser, it should go to the address 192.168.1.100 instead of looking it up on the internet.
Lines that start with a # symbol are comments — your computer ignores them. People use comments to explain what each entry does, or to temporarily disable an entry without deleting it.
Common reasons to edit the host file
Web developers often add entries to the host file to test a website on their own computer before it goes live on the internet. They might add a line like 127.0.0.1 newsite.com so that typing newsite.com in their browser loads their local test version instead of the real website.
Some people add entries to block websites from loading. For example, 127.0.0.1 facebook.com will prevent your browser from reaching Facebook — it will try to connect to your own computer instead and fail. This is a crude form of blocking and does not survive a restart if you use a different DNS service, but it works as a quick barrier.
Troubleshooting is another reason. If a website will not load and you suspect a DNS problem, you can check the host file to see whether something is redirecting that domain to the wrong address. Malware sometimes modifies the host file to redirect you to fake versions of banking or email sites.
How to edit and save the host file safely
Before you make any changes, save a backup copy. With the host file open in your text editor, go to File and select Save As. Save it to your Desktop or Documents folder with a name like hosts_backup. That way, if something goes wrong, you can copy the original back.
To add a new entry, go to the end of the file and press Enter to create a new line. Type the IP address, press Tab, then type the domain name. For example: 192.168.1.50 testsite.local. Do not add extra spaces — use a single Tab character between the IP and the domain name.
When you are done, save the file. In Notepad or gedit, press Ctrl + S (or Command + S on Mac). In nano, press Ctrl + O, press Enter to confirm the filename, then press Ctrl + X to exit. Changes take effect immediately — you do not need to restart your computer or your browser.
If you make a mistake and a website stops working, open the host file again and remove or fix the line you added. A single typo — a space instead of a Tab, or a misspelled domain — can break everything. If you cannot figure out what went wrong, delete all your custom entries and restore from your backup.
Frequently Asked Questions
Do I need to restart my computer after editing the host file?
No. Changes to the host file take effect immediately. You may need to close and reopen your browser, or clear your browser cache, but you do not need to restart your computer. If a change does not seem to work, try opening your browser in a private or incognito window, which bypasses the cache.
What if I cannot save changes to the host file?
You likely do not have administrator or root access. On Windows, close your text editor, right-click Notepad itself, select Run as administrator, and open the file again. On Mac or Linux, make sure you used the sudo command when opening the file. If you still cannot save, your system may have restrictions that prevent editing system files.
Can the host file get infected with malware?
Yes. Malware sometimes modifies the host file to redirect you to fake websites that look real but steal your login information. If you notice websites redirecting to strange places, open the host file and look for entries you did not add. Delete any suspicious lines and save the file. If you cannot fix it, restore from your backup or contact technical support.
What is the difference between the host file and DNS?
The host file is checked first, before your computer even asks the internet. DNS is the internet-wide system that looks up domain names when they are not in your host file. If an entry is in your host file, DNS is never consulted for that domain.
Can I use the host file to block ads or tracking?
Yes, but it is not the most practical way. You would need to add hundreds or thousands of entries for every ad network and tracking domain. Browser extensions and DNS-level blockers do this job more efficiently. The host file works better for blocking one or two specific sites, or for testing local websites.