The hosts file in Windows is a simple yet powerful tool that lets you manually map hostnames (like websites) to specific IP addresses. It’s often used by developers, network administrators, and power users to block websites, test domains, or override DNS resolutions.
However, sometimes users find that the hosts file stops working — changes made to it don’t take effect, websites aren’t redirected, or Windows ignores it altogether. This can happen for several reasons, such as incorrect file formatting, permission issues, or DNS caching problems.
In this guide, we’ll walk you through the most effective ways to fix the hosts file not working issue in Windows 11.
Common Reasons Why the Hosts File Doesn’t Work
Here are the most common causes behind this problem:
- Incorrect file path or syntax in the hosts file
- Insufficient administrator permissions when editing
- Windows Defender or antivirus blocking the file
- Cached DNS entries overriding hosts file rules
- Hidden file extensions or encoding errors (UTF-8 with BOM)
- Missing or corrupted hosts file
Now, let’s go through the solutions step-by-step.
1. Verify the Hosts File Location
First, make sure you’re editing the correct hosts file. On Windows 11, the hosts file is stored in the following path:
C:\Windows\System32\drivers\etc\hosts
- Open File Explorer and navigate to the path above.
- Right-click the hosts file and choose Open with → Notepad.
- Make sure your changes are in this file — not in a copy saved elsewhere (like your desktop).
If you’re editing a duplicate file, Windows won’t recognize your changes.
2. Run Notepad as Administrator
If you edit the hosts file without admin privileges, Windows won’t save the changes correctly, even if it looks like it did.
To properly edit the file:
- Press Windows + S, type Notepad, and select Run as administrator.
- In Notepad, click File → Open.
- Navigate to:
C:\Windows\System32\drivers\etc - Change the file type from Text Documents (.txt) to All Files.
- Select the hosts file and open it.
- Make your edits and click File → Save.
Then, restart your browser or PC and check if your changes are taking effect.
3. Check File Format and Encoding
The hosts file must be saved as a plain text file with ANSI encoding (or UTF-8 without BOM) — otherwise, Windows may not read it correctly.
To fix the format:
- Open the hosts file in Notepad.
- Go to File → Save As.
- At the bottom, ensure:
- Save as type: All Files
- Encoding: ANSI or UTF-8 (without BOM)
- File name:
hosts(without.txtextension)
- Save it back in:
C:\Windows\System32\drivers\etc - Replace the existing file if prompted.
Avoid using WordPad or third-party editors that might change the encoding format automatically.
4. Flush the DNS Cache
Even after editing the hosts file, Windows might still use cached DNS data, ignoring your new entries. Flushing the DNS cache forces Windows to reload host mappings.
- Press Windows + S, type cmd, and select Run as administrator.
- Run the following command:
ipconfig /flushdns - You’ll see a confirmation message:
Successfully flushed the DNS Resolver Cache.
After that, restart your browser or computer and check if your changes now work.
5. Disable DNS Client Service (Optional)
Windows uses the DNS Client service to cache DNS lookups, which can sometimes bypass hosts file entries entirely. Disabling it forces Windows to consult the hosts file directly each time.
- Press Windows + R, type:
services.mscand hit Enter. - Scroll down and find DNS Client.
- Right-click it → Properties.
- Set Startup type to Disabled.
- Click Stop, then Apply → OK.
Restart your system and test if the hosts file changes are now reflected.
Note: Disabling the DNS Client may slightly slow down name resolutions, so re-enable it after troubleshooting if necessary.
6. Temporarily Disable Antivirus or Windows Defender
Some antivirus programs (including Windows Defender) protect system files like the hosts file from modification to prevent malware tampering.
If your changes aren’t being saved or recognized, temporarily disable real-time protection to edit the file:
For Windows Defender:
- Press Windows + I → Privacy & security → Windows Security → Virus & threat protection.
- Click Manage settings under Virus & threat protection settings.
- Toggle Real-time protection to Off.
Make your changes to the hosts file, save it, and test.
Once confirmed, re-enable protection immediately.
If you use third-party antivirus software, open its dashboard and look for a setting like “Hosts file protection” or “System file monitoring.”
7. Check File Permissions
If your user account doesn’t have proper permissions, Windows might block access to the hosts file.
To fix this:
- Navigate to:
C:\Windows\System32\drivers\etc - Right-click the hosts file → Properties → Security tab.
- Click Edit → Add, and type your username.
- Grant Full control permissions.
- Click Apply → OK.
Now try editing and saving the hosts file again with admin rights.
8. Ensure Correct Syntax Inside the Hosts File
Even a small syntax error (like an extra space or missing IP address) can cause the hosts file to fail.
Here’s the correct format:
127.0.0.1 example.com
0.0.0.0 ads.example.com
Make sure:
- Each entry has an IP address followed by at least one space or tab.
- Lines starting with
#are comments and ignored by Windows. - No extra file extensions (like
.txt) are added accidentally.
After editing, save the file and flush DNS again using:
ipconfig /flushdns
9. Reset the Hosts File to Default
If the file has become too corrupted or misconfigured, restoring it to its default state can fix the issue.
1. Open Notepad as administrator.
2. Paste the following default content:
# Copyright (c) Microsoft Corporation.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
#
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
3. Save it as hosts in: C:\Windows\System32\drivers\etc
4. Overwrite the old file and restart your PC.
You can now re-add your custom entries carefully.
10. Reset Network Settings
If all else fails, resetting Windows network configurations can restore normal hosts file behavior.
- Press Windows + I → Network & internet → Advanced network settings → Network reset.
- Click Reset now.
- Restart your computer when prompted.
This clears cached configurations and resets DNS and TCP/IP settings, allowing your hosts file to function properly again.
Wrapping Up
If your hosts file isn’t working in Windows 11, it’s usually due to incorrect permissions, bad formatting, or DNS caching.
Start by verifying the file path and editing it with administrator rights, then flush DNS and check the encoding format. In most cases, these simple steps resolve the problem. If not, resetting the file or network settings will almost always restore functionality.
Once fixed, your hosts file should correctly map domains to IP addresses, allowing you to test, block, or redirect websites as intended.