The host file location on Windows
The Windows host file is stored at C:\Windows\System32\drivers\etc\hosts on every Windows computer. It has no file extension — the name is simply "hosts". You cannot find it by browsing normally because Windows hides system files by default, and the file sits several folders deep in a protected directory.
The host file is a plain text document that your computer checks before it looks up web addresses on the internet. When you type a website into your browser, Windows first checks this file to see if there is a matching address. If it finds one, it uses that instead of asking a DNS server. This is why system administrators and developers use it to block websites, test local servers, or redirect traffic.
Because the file controls how your computer connects to the internet, Windows protects it — you need administrator permission to edit it, and you cannot simply double-click it to open it like a normal document.
Key Takeaways
- The host file is located at C:\Windows\System32\drivers\etc\hosts and has no file extension.
- You must open it with administrator permission using a text editor like Notepad, not by double-clicking it.
- The fastest route is to right-click Notepad, select "Run as administrator", then use File > Open to navigate to the hosts file.
- You can also use the Run dialog (Windows key + R) to jump directly to the folder containing the hosts file.
- Any changes you make take effect immediately without restarting, though some browsers cache DNS lookups and may need to be closed and reopened.
Opening the hosts file with Notepad
The simplest way to open the host file is through Notepad with administrator rights. Right-click the Notepad icon on your Start menu or taskbar and select "Run as administrator". Windows will ask for permission — click "Yes" to continue.
Once Notepad opens, click File in the menu bar, then Open. In the dialog that appears, navigate to C:\Windows\System32\drivers\etc\. By default, Notepad shows only .txt files, so you will not see the hosts file listed. At the bottom of the Open dialog, change the dropdown that says "Text Documents (*.txt)" to "All Files (*.*)" instead. Now the hosts file will appear in the list. Click it and select Open.
If you cannot see the etc folder when you navigate to System32, Windows is still hiding system files. In the Open dialog, click View in the menu bar and check the box next to "Hidden items". The etc folder will now appear.
Using the Run dialog to jump directly to the folder
A faster route if you open the hosts file often is to use the Run dialog. Press Windows key + R on your keyboard. A small dialog box will appear. Type the full path to the hosts file folder: C:\Windows\System32\drivers\etc and press Enter.
File Explorer will open and show you the contents of the etc folder. You will see the hosts file listed. Right-click it, select "Open with", then choose Notepad. A dialog will appear asking for administrator permission — click "Yes".
This method is faster than navigating through folders manually, but it still requires you to right-click and choose "Open with" because double-clicking the hosts file will not work — Windows will either show an error or open it in a program that cannot save changes.
Using Command Prompt or PowerShell as administrator
If you are comfortable with the command line, you can open the hosts file directly from Command Prompt or PowerShell. Right-click Command Prompt or PowerShell in your Start menu and select "Run as administrator". Click "Yes" when asked for permission.
In the command window, type: notepad C:\Windows\System32\drivers\etc\hosts and press Enter. Notepad will open with the hosts file already loaded. This method skips the navigation steps entirely and is the fastest route if you use the command line regularly.
You can also use other text editors this way. For example, typing code C:\Windows\System32\drivers\etc\hosts will open the file in Visual Studio Code if you have it installed. The key is that you must run the command window itself as administrator, not just the text editor.
What to do after you open the hosts file
Once the hosts file is open in Notepad, you will see lines that start with numbers and website addresses. Each line tells your computer to send a specific web address to a specific IP address. The most common entry is 127.0.0.1 localhost, which points to your own computer.
To add a new entry, go to the end of the file and press Enter to create a new line. Type the IP address, then press Tab or Space, then type the website address. For example, to block a website, you would type 127.0.0.1 example.com. Save the file by pressing Ctrl + S or clicking File > Save.
Changes to the hosts file take effect immediately. You do not need to restart your computer. However, your web browser may have cached the old address, so close the browser completely and reopen it to see the change. Some browsers require you to clear the DNS cache separately — in Chrome, you can do this by typing chrome://net-internals/#dns in the address bar and clicking "Clear host cache".
Backing up the hosts file before editing
Before you make changes to the hosts file, create a backup copy. In File Explorer, navigate to C:\Windows\System32\drivers\etc\, right-click the hosts file, and select "Copy". Right-click in the same folder and select "Paste". A copy named "hosts - Copy" will appear. Keep this file in the same folder as a safety net.
If something goes wrong after your changes — for example, you cannot reach a website you need — you can restore the original by deleting your edited version and renaming the backup back to "hosts". This is much faster than trying to remember what you changed.
Windows also keeps a system backup of the hosts file, but accessing it requires more steps. Keeping your own copy in the same folder is the simplest insurance against mistakes.
Frequently Asked Questions
Why can't I just double-click the hosts file to open it?
Double-clicking the hosts file will not work because Windows does not have a default program set to open it. Even if you force it to open in Notepad by right-clicking and selecting "Open with", you will not be able to save your changes without administrator permission. Right-clicking and selecting "Open with" or opening Notepad as administrator first is the only way to edit and save the file.
Do I need to restart my computer after changing the hosts file?
No. Changes to the hosts file take effect immediately without a restart. However, your web browser may have cached the old DNS lookup, so close the browser completely and reopen it. Some browsers also require you to clear their DNS cache separately through their settings or built-in tools.
What if I accidentally delete or corrupt the hosts file?
If you have a backup copy, simply delete the corrupted file and rename the backup back to "hosts". If you do not have a backup, Windows can restore a clean version through System Restore or you can manually recreate it with just the line "127.0.0.1 localhost". For most users, the hosts file contains only this one line by default.
Can I edit the hosts file on a network drive or external drive?
No. The hosts file must be on your local C: drive at C:\Windows\System32\drivers\etc\hosts for Windows to read it. Your computer checks only this location, so editing a copy on another drive will have no effect.
What is the difference between the hosts file and DNS settings?
The hosts file is checked first and only on your local computer. DNS settings control which server your computer asks when the hosts file does not have an answer. The hosts file overrides DNS, so if you add an entry there, it will be used instead of whatever your DNS server says.