The hosts file location in Windows
The hosts file is a text file that your computer checks before it looks up a website's address on the internet. It sits in a specific Windows folder that is hidden by default, which is why many people never see it. On every version of Windows, the file is located at C:\Windows\System32\drivers\etc\hosts — no file extension, just "hosts".
This file contains a list of domain names (like google.com) paired with IP addresses. When you type a web address into your browser, Windows checks this file first. If it finds a match, it uses that IP address instead of asking the internet. This is why the hosts file is useful for blocking websites, testing websites before they go live, or redirecting traffic on your own machine.
Because the file is hidden and sits deep in a system folder, Windows makes it deliberately hard to find and edit. You cannot straightforward open File Explorer and navigate there without first turning on the display of hidden files, or you can use a direct path to jump straight to it.
Key Takeaways
- The hosts file is located at C:\Windows\System32\drivers\etc\hosts on all Windows versions and contains no file extension.
- You must run Notepad as administrator before you can save changes to the hosts file, because it is a protected system file.
- The simplest way to open it is to press Windows key + R, type the full path, and press Enter — no need to hunt through folders.
- After you edit the hosts file, you may need to flush your DNS cache by opening Command Prompt as administrator and typing ipconfig /flushdns.
Opening the hosts file with the Run dialog
The fastest way to reach the hosts file is to use the Run dialog. Press the Windows key and R at the same time. A small box will appear. Type the full path: C:\Windows\System32\drivers\etc\hosts and press Enter.
Windows will ask you which program you want to use to open it. Select Notepad from the list. If Notepad does not appear, click "More apps" and scroll down until you find it. Do not use Word or any other word processor — they add formatting that will break the file. Notepad is plain text only, which is what the hosts file needs.
If a dialog appears saying you do not have permission to open the file, close Notepad and try again. This time, right-click on Notepad in your Start menu and select "Run as administrator" before you open the file path. Administrator mode gives you the permission you need to edit a system file.
Navigating through File Explorer if you prefer
If you want to see the file in a folder instead of using the Run dialog, you can navigate there through File Explorer. First, you must turn on the display of hidden files, because the etc folder is hidden. Open File Explorer, click the "View" tab at the top, and check the box next to "Hidden items". Now hidden files and folders will appear.
Next, navigate to C:\Windows\System32\drivers\etc. You can type this path directly into the address bar at the top of File Explorer, or click through each folder one at a time. When you reach the etc folder, you will see the hosts file. Right-click it and select "Open with" and then "Notepad". Again, make sure Notepad runs as administrator, or you will not be able to save your changes.
Understanding the format inside the hosts file
When you open the hosts file, you will see lines that look like this: 127.0.0.1 localhost. The first part is an IP address. The second part is a domain name. These two are separated by a space or a tab. When your computer sees that domain name, it will use that IP address instead of looking it up online.
Lines that start with a hash symbol (#) are comments and do not do anything — Windows ignores them. You can add your own comments to explain what each line does. For example: # Block social media 127.0.0.1 facebook.com.
To block a website, add a new line with 127.0.0.1 (which points to your own computer) followed by the domain name. To redirect a website to a different address, use that address instead of 127.0.0.1. Each domain should be on its own line. Do not add extra spaces or change the format, or the line will not work.
Saving your changes and making them take effect
After you edit the hosts file, click File and then Save. If you get a permission error, you did not open Notepad as administrator — close the file without saving, open Notepad as administrator, and try again. Once the file saves, close Notepad.
Your changes take effect when ready for most purposes, but your browser may have cached the old address. To clear this cache, open Command Prompt as administrator. Press Windows key + R, type cmd, and press Ctrl + Shift + Enter to run it as administrator. Then type ipconfig /flushdns and press Enter. This clears the DNS cache and forces your computer to check the hosts file again.
If you are testing a website, close your browser completely and reopen it after you flush the DNS cache. Some browsers hold onto cached addresses even after the cache is flushed if they are still running.
Common reasons the hosts file does not work
If you edited the hosts file but the change did not take effect, the most common cause is a formatting error. Make sure there is only one space or tab between the IP address and the domain name. Check that you did not accidentally add extra spaces at the end of the line. Even one extra space will break it.
Another common issue is forgetting to flush the DNS cache. Your computer remembers old addresses, so it may ignore the new entry in the hosts file until you run ipconfig /flushdns. If you are blocking a website, also check that you used 127.0.0.1 and not some other IP address — 127.0.0.1 is the loopback address that points to your own machine.
If you are trying to redirect a domain to a different website, make sure you used the correct IP address for that website. You can find a website's IP address by opening Command Prompt and typing nslookup example.com (replace example.com with the actual domain). The result will show you the IP address to use.
Restoring the hosts file to its default state
If you made changes to the hosts file and want to undo them, you can restore it to the default. Open Notepad as administrator and open the hosts file again. Delete all the lines you added, keeping only the default lines that were there when you first opened it. The default hosts file usually contains only a few lines, including 127.0.0.1 localhost and possibly ::1 localhost (the IPv6 version).
If you accidentally deleted something important and cannot remember what was there, you can restore the file from a system backup. Right-click the hosts file, select "Restore previous versions", and choose a date before you made your changes. If no previous versions are available, your system does not have backups turned on. In that case, you can manually recreate the default file by keeping only the localhost lines and deleting everything else you added.
Frequently Asked Questions
Can I edit the hosts file on Windows 11 the same way as Windows 10?
Yes. The hosts file location and editing process are identical on Windows 11, Windows 10, Windows 8, and Windows 7. The path is always C:\Windows\System32\drivers\etc\hosts, and you always need to run Notepad as administrator to save changes.
What happens if I delete the hosts file entirely?
Windows will still work, but you may see errors if any programs depend on the localhost entry. It is safer to leave the default lines in place and only delete the entries you added. If you do delete it by accident, you can restore it from a previous version or recreate it with just the localhost lines.
Do I need to restart my computer after editing the hosts file?
No. Running ipconfig /flushdns in Command Prompt is enough. Your changes take effect when ready after you flush the DNS cache. You only need to restart your browser if it is still running.
Can I use the hosts file to block ads?
Yes, but it is not the most practical way. You would need to add hundreds or thousands of ad server domains to the hosts file manually. Browser extensions and ad blockers do this automatically and are much easier to maintain. The hosts file works better for blocking one or two specific sites or testing your own websites.
Will antivirus software interfere with editing the hosts file?
Some antivirus programs monitor the hosts file and may block changes or alert you when you edit it. This is normal — they are protecting your system from malware that tries to redirect websites. If your antivirus blocks your edit, you may need to temporarily disable it, make your change, and then turn it back on. Check your antivirus settings to see if there is an option to allow hosts file edits.