Fix Hosts File Not Working in Windows 11
In this article
- Why Windows 11 Ignores Your Hosts File
- Fix 1: Run Your Editor as Administrator
- Fix 2: Take Ownership and Set Permissions
- Fix 3: Flush DNS Cache and Reset Network Stack
- Fix 4: Check File Encoding and Format
- Fix 5: Disable DNSCrypt or Third-Party DNS Services
- Fix 6: Use the Correct Syntax and IP Version
- Frequently Asked Questions
If your edits to the hosts file in Windows 11 are being ignored, the most common causes are file permission issues, DNS caching, or the file being saved with the wrong encoding. This guide walks through each fix in order, from checking file permissions to flushing DNS, so you can get your custom host mappings working again.
Why Windows 11 Ignores Your Hosts File
The hosts file is a plain-text file that maps hostnames to IP addresses before any DNS lookup happens. Windows 11 reads it at boot and when network settings change, but it doesn't continuously watch the file. So if you edit it and immediately try to browse, you may still get the old result until you flush the DNS cache or restart the network adapter.
Another common reason is that Windows 11 treats the hosts file as a protected system file. Even if you are an administrator, editing it with a normal text editor like Notepad can fail silently—the file appears to save, but Windows actually blocks the write. This happens because the file's ACL (access control list) only grants write permission to the SYSTEM account and the Administrators group, but the editor process may not be running with those elevated rights.
Fix 1: Run Your Editor as Administrator
The first and most frequent fix is to launch your text editor with elevated privileges. Notepad, Notepad++, VS Code, or any editor must be run as administrator to modify the hosts file.
- Click the Start button, type Notepad (or your preferred editor).
- Right-click the app in the search results and select Run as administrator.
- In the editor, go to File → Open and navigate to
C:\Windows\System32\drivers\etc. - Change the file type filter from “Text Documents” to All Files so you can see the
hostsfile. - Open the file, make your edits, and save.
If you still get an “Access denied” error, you may need to take ownership of the file first (see Fix 2).
Fix 2: Take Ownership and Set Permissions
Sometimes the ACL on the hosts file is corrupted or overly restrictive. Taking ownership and granting your user account full control is a reliable way to fix this.
- Open File Explorer and go to
C:\Windows\System32\drivers\etc. - Right-click the
hostsfile and select Properties. - Go to the Security tab, then click Advanced.
- Next to “Owner,” click Change.
- Type your Windows username, click Check Names, then OK.
- Check the box Replace owner on subcontainers and objects (if available) and click OK.
- Back in the Security tab, select your user, click Edit, and check Full control.
- Apply the changes and try editing again.
Be careful: granting full control to the hosts file is safe, but don’t change permissions on other system files unless you know what you’re doing.
Fix 3: Flush DNS Cache and Reset Network Stack
Even after a correct edit, Windows may still use the cached DNS result. Flushing the DNS cache forces the system to re-read the hosts file.
- Open Command Prompt as administrator (right-click Start → Terminal (Admin)).
- Type
ipconfig /flushdnsand press Enter. - If you still see old results, also run
ipconfig /registerdnsandnetsh winsock reset. - Restart your computer or disable/enable your network adapter.
Note that some applications (like browsers) have their own DNS cache. Chrome, for example, has a built-in DNS cache that you can clear by visiting chrome://net-internals/#dns and clicking “Clear host cache.”
Fix 4: Check File Encoding and Format
Windows 11 expects the hosts file to be saved in ANSI or UTF-8 without BOM (Byte Order Mark). If you save it with UTF-8 BOM, the first line may be misinterpreted, causing the entire file to be ignored.
- Use Notepad and choose ANSI or UTF-8 (without BOM) in the “Save As” dialog.
- Do not use tabs or trailing spaces after entries.
- Each mapping should be on its own line: IP address, a space or tab, then the hostname.
- Use
#for comments. Never put a comment on the same line as a mapping.
Also, make sure you are not accidentally saving the file as hosts.txt or hosts.txt.txt. In the Save dialog, set “Save as type” to All Files and type the name as hosts (no extension).
Fix 5: Disable DNSCrypt or Third-Party DNS Services
If you use a third-party DNS client like DNSCrypt, or a VPN with its own DNS settings, those services may bypass the hosts file entirely. Windows 11's built-in DNS resolver checks the hosts file first, but external DNS software can override that.
To test, temporarily disable your VPN or DNS client and see if your hosts entries work. If they do, you'll need to configure that software to respect the hosts file, or add your mappings in its own configuration.
Fix 6: Use the Correct Syntax and IP Version
Windows 11 supports both IPv4 and IPv6 in the hosts file. If you map a hostname to an IPv4 address (like 127.0.0.1) but the application tries to resolve it as IPv6, it may not match.
- For localhost, both
127.0.0.1and::1are preconfigured. - If you want to block a site, you can map it to
0.0.0.0or::(unspecified address). - Always test with
pingornslookupafter editing.
Also, ensure you are not using a wildcard or regex—hosts file only supports exact hostnames, not patterns.
Frequently Asked Questions
Why does my hosts file edit not work even after saving?
Most likely you didn't run the editor as administrator, so the file wasn't actually saved. Check the file's modification time in File Explorer. If it didn't change, repeat the edit with elevated privileges.
Do I need to restart after editing the hosts file?
Not always, but flushing DNS and restarting the browser is usually enough. If the mapping still doesn't work, a full restart ensures all services re-read the file.
Can I use the hosts file to block websites?
Yes, mapping a domain to 0.0.0.0 or :: effectively blocks it, but it only works for the exact hostname. Many sites use multiple subdomains, so you'd need to add each one.
Why does Windows 11 reset my hosts file?
Windows doesn't reset it automatically, but some security software or “cleanup” tools might. Also, if you edit the file while it's open in another program, you might overwrite changes.
Is editing the hosts file safe?
Yes, if you only add mappings for hosts you control or want to block. Incorrect entries can break internet access for that hostname, but you can always remove them. Avoid adding entries for system-critical domains unless you know what you're doing.