Hosts File Not Working Windows: Fix It Fast
In this article
The hosts file is not working on Windows primarily because the system DNS cache is holding onto old records, or because the file lacks proper administrative permissions. To fix this immediately, you must edit the file as an administrator and then flush the DNS cache using the command prompt. This process forces Windows to reload your custom domain mappings.
What You'll Need
- A Windows PC running Windows 10 or Windows 11
- Administrator access to your user account
- Notepad (built-in text editor)
- Command Prompt (run as Administrator)
Step-by-Step
- Locate the Hosts File: Open your File Explorer and navigate to the following directory path:
C:\Windows\System32\drivers\etc. You will see a file namedhostswith no extension. - Open with Notepad as Admin: Right-click the Start button, select Terminal (Admin) or Command Prompt (Admin), and type
notepadfollowed by pressing Enter. Alternatively, search for Notepad in the start menu, right-click it, and choose Run as administrator. In Notepad, go to File > Open. - Select the Correct File Type: In the Open dialog box, look at the bottom right where it says "Text Documents (*.txt)". Click that dropdown menu and select All Files (*.*). This is crucial; otherwise, you won't see the hosts file.
- Navigate and Open: Browse to
C:\Windows\System32\drivers\etcand select thehostsfile. Click Open. - Edit the Entries: Scroll to the very bottom of the file. Add your new entries on new lines using the format:
IP_Address Domain_Name. For example:127.0.0.1 localhost. Ensure there are no spaces between the IP and the domain, but use a single space between them if required by your specific setup. - Save the File: Press Ctrl + S or go to File > Save. If you get a permission error, ensure you opened Notepad with Administrator privileges in Step 2.
- Flush the DNS Cache: Open Command Prompt as Administrator again. Type the following command and press Enter:
ipconfig /flushdns. You should see a message confirming "Successfully flushed the DNS Resolver Cache." - Verify the Change: Open your web browser and visit the domain you just mapped. If it loads the local IP or redirects correctly, the hosts file is now working.
Common Mistakes
The most frequent reason users believe their hosts file is broken is failing to run the editor as an administrator. Windows protects system files in the System32 folder, so standard user accounts cannot save changes directly to it. Another common error is forgetting to flush the DNS cache. Windows caches DNS lookups aggressively to speed up browsing; without flushing, the system continues to use the old cached record even after you have edited the file.
Additionally, many users accidentally add comments or syntax errors. Lines starting with a hash symbol (#) are ignored by Windows. Ensure your active entries do not start with #. Also, avoid adding extra spaces or tabs that might break the IP-to-domain mapping logic.
Tips
Always keep a backup of your original hosts file before making changes. Copy the existing file to your desktop and rename it to hosts.backup. If something goes wrong, you can simply drag it back into the system folder. When testing multiple domains, group them logically with comments above each section to keep the file readable. Use 127.0.0.1 for local testing or 0.0.0.0 to block sites entirely by redirecting them to a non-routable address.
Troubleshooting
If the hosts file still does not work after following the steps above, perform these checks in order. First, verify that your antivirus or firewall software is not intercepting network traffic. Some security suites have a "web protection" feature that overrides local DNS settings. Temporarily disable such features to test.
Second, check for duplicate entries. If you have two lines for the same domain, Windows typically uses the first one it encounters. Ensure there are no conflicting IPs listed earlier in the file. Third, restart your computer. A full reboot clears all network states and ensures the new configuration is loaded from disk. Finally, if you are using third-party DNS software or virtualization tools like Docker, they may manage their own local DNS resolvers, bypassing the Windows hosts file entirely.
Frequently Asked Questions
Why does my browser still show the old site?
Browsers often maintain their own internal DNS cache separate from the OS. Try clearing your browser cache or opening an Incognito/Private window to force a fresh lookup.
Can I edit the hosts file on Windows 11?
Yes, the process is identical to Windows 10. The file location and permissions remain the same across modern Windows versions.
Does the hosts file affect HTTPS sites?
Yes, it affects all domains regardless of protocol. However, if the IP you map has an SSL certificate that doesn't match the domain name, your browser will show a security warning.
How do I unblock a website I previously blocked?
Open the hosts file again, find the line containing the domain you want to unblock, and either delete that line or comment it out by adding a # at the beginning. Then flush the DNS cache.
Is it safe to modify the hosts file?
It is completely safe. The file is a standard system configuration file. As long as you only modify valid IP addresses and domain names, it poses no risk to your system stability.