Hosts File Location Windows 11: C:\Windows\System32\drivers\etc\hosts
Exact hosts file path on Windows 10/11 and 24H2: C:\Windows\System32\drivers\etc\hosts. Edit with Notepad or PowerShell, flush DNS, and fix access denied.
Sleezr Team

Table of Contents
- Windows 10 vs Windows 11
- Hosts file location on Windows 11 (exact path)
- How to edit the hosts file on Windows 10 & 11
- Method 1: Notepad as administrator (recommended for beginners)
- Method 2: PowerShell / Windows Terminal (recommended for developers)
- Open hosts file directly
- Append an entry without opening an editor
- View current hosts file content
- Flush DNS from the same terminal
- Back up before editing
- Method 3: VS Code as administrator
- Flush DNS on Windows 11
- Verify changes
- Windows 11-specific troubleshooting
- Controlled Folder Access blocks save
- Smart App Control restrictions
- Changes revert after Windows Update
- DNS over HTTPS bypassing hosts file
- Access denied despite running as admin
- Comparison of the three methods
- Example entries for common Windows 11 dev setups
- WSL 2 and the Windows hosts file
- Windows 11 Dev Drive and protected folders
- Scheduled tasks and startup scripts
- Troubleshooting Windows 11 24H2 specifically
- When to use a GUI instead of manual editing
- Best practices on Windows 11
- Related guides
- Sources and further reading
Hosts file location on Windows 11 (same as Windows 10):
C:\Windows\System32\drivers\etc\hostsPaste that path into File Explorer’s address bar or Win+R to open the etc folder. The file is named hosts with no extension. Writing to it requires administrator rights. Everything below shows how to open, edit, and apply changes safely.
Windows 10 vs Windows 11
| Windows 10 | Windows 11 | |
|---|---|---|
| Hosts path | C:\Windows\System32\drivers\etc\hosts | Same |
| Default editor | Notepad as admin | Notepad or Windows Terminal as admin |
| DNS flush | ipconfig /flushdns | Same + Clear-DnsClientCache in PowerShell |
| Extra gotchas | Defender rarely blocks | Controlled Folder Access, 24H2 Smart App Control |
Everything below applies to Windows 10, Windows 11, and 24H2 unless noted. 24H2-only security fixes (Smart App Control, Controlled Folder Access) are covered in the troubleshooting section below. Need the path without admin write access? See edit hosts without admin. Cross-platform overview: Main hosts guide.
Hosts file location on Windows 11 (exact path)
The host file path in Windows 11 is always:
C:\Windows\System32\drivers\etc\hosts- Folder:
C:\Windows\System32\drivers\etc - File:
hosts(no.txtextension) - Fast open: Win+R → paste the folder path → Enter → open
hostswith an elevated editor - Notepad tip: set the Open dialog filter to **All Files (*.*)** or the file stays hidden
Unchanged since Windows XP. Same path on Windows 10 and Windows 11.
How to edit the hosts file on Windows 10 & 11
To edit the hosts file on Windows 11, run a text editor as administrator and save to C:\Windows\System32\drivers\etc\hosts:
C:\Windows\System32\drivers\etc, set the filter to All Files, and open hosts.127.0.0.1 mysite.test.ipconfig /flushdns.The PowerShell method and Windows 11 security notes are below.
Method 1: Notepad as administrator (recommended for beginners)
This method works identically on Windows 10 and 11.
C:\Windows\System32\drivers\etc127.0.0.1 myproject.test
127.0.0.1 api.myproject.testMethod 2: PowerShell / Windows Terminal (recommended for developers)
Windows 11 ships with Windows Terminal pre-installed, use it for faster workflows.
Open hosts file directly
notepad C:\Windows\System32\drivers\etc\hostsNotepad opens with the file loaded. Edit, save, close.
Append an entry without opening an editor
Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1 newsite.test"View current hosts file content
Get-Content C:\Windows\System32\drivers\etc\hostsFlush DNS from the same terminal
ipconfig /flushdns
# Or on Windows 11 24H2:
Clear-DnsClientCacheBack up before editing
Copy-Item C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\hosts.backupMethod 3: VS Code as administrator
Developers who prefer syntax highlighting and multi-cursor editing:
C:\Windows\System32\drivers\etc\hostsTip: Pin an admin VS Code shortcut to your taskbar for frequent hosts file work.
Alternatively, open Terminal as admin and run:
code C:\Windows\System32\drivers\etc\hosts(VS Code must already be running as administrator for this to work.)
Flush DNS on Windows 11
After every hosts file edit:
ipconfig /flushdnsOr in PowerShell:
Clear-DnsClientCacheThen clear browser cache if needed:
- Chrome/Edge:
chrome://net-internals/#dns→ Clear host cache - Firefox:
about:networking#dns→ Clear DNS Cache
Verify changes
ping myproject.test
nslookup myproject.testBoth should return 127.0.0.1 (or whatever IP you configured).
Windows 11-specific troubleshooting
Controlled Folder Access blocks save
Windows 11 Controlled Folder Access (ransomware protection) can block writes to protected folders.
Fix:
Smart App Control restrictions
Smart App Control may block unsigned third-party hosts editors. Built-in Notepad and Microsoft-signed VS Code are unaffected when run as administrator.
Changes revert after Windows Update
Some Windows Updates reset the hosts file to default. Keep a backup:
Copy-Item C:\Windows\System32\drivers\etc\hosts $env:USERPROFILE\Documents\hosts.backupRestore after update:
Copy-Item $env:USERPROFILE\Documents\hosts.backup C:\Windows\System32\drivers\etc\hostsDNS over HTTPS bypassing hosts file
If Chrome or Edge has Secure DNS enabled (Settings → Privacy → Use secure DNS), it may bypass the local hosts file for some lookups.
Fix: Disable secure DNS temporarily while testing, or use ping and nslookup for verification instead of browser-only tests.
Access denied despite running as admin
Check whether a third-party antivirus (Norton, McAfee, Kaspersky) protects the hosts file. Temporarily disable "hosts file protection" in the antivirus settings.
See Edit hosts file as administrator for a full permissions breakdown.
Comparison of the three methods
| Method | Best for | Pros | Cons |
|---|---|---|---|
| Notepad (admin) | Beginners, one-off edits | Simple, always available | No syntax highlighting |
| PowerShell/Terminal | Developers, scripts | Fast, scriptable, backup commands | Requires terminal comfort |
| VS Code (admin) | Large files, many entries | Search, replace, extensions | Must launch as admin |
Example entries for common Windows 11 dev setups
Local WordPress/Laravel:
127.0.0.1 mysite.test
127.0.0.1 www.mysite.testBlock distractions:
0.0.0.0 twitter.com
0.0.0.0 www.twitter.comSee Block a website with the hosts file.
Staging server override:
203.0.113.50 client.com
203.0.113.50 www.client.comWSL 2 and the Windows hosts file
Windows Subsystem for Linux (WSL 2) has its own /etc/hosts inside the Linux VM, separate from the Windows hosts file. Entries you add in Windows Notepad do not automatically apply inside WSL.
To use the same local domains in WSL:
# Inside WSL, edit the Linux hosts file
sudo nano /etc/hosts
# Add the same entries as WindowsAlternatively, configure .wslconfig or use host.docker.internal for Docker-on-WSL workflows. Many full-stack developers maintain identical entries in both Windows and WSL hosts files, or use a sync script in their dev environment setup.
Windows 11 Dev Drive and protected folders
Windows 11 Dev Drive optimizes performance for development workloads but does not change hosts file behavior, the file remains in System32 regardless of where your projects live. Controlled Folder Access, however, can block editors even when run as administrator if they are not on the allowed list. Add your preferred editor once during initial setup to avoid repeated permission surprises.
Scheduled tasks and startup scripts
Teams that deploy standard dev environments sometimes distribute hosts snippets via login scripts or Intune configuration profiles. For personal automation, a PowerShell profile function speeds up repetitive edits:
function Add-HostsEntry($ip, $domain) {
$line = "$ip $domain"
$path = "C:\Windows\System32\drivers\etc\hosts"
if (-not (Select-String -Path $path -Pattern [regex]::Escape($domain) -Quiet)) {
Add-Content -Path $path -Value $line
Clear-DnsClientCache
Write-Host "Added: $line"
}
}
# Usage: Add-HostsEntry "127.0.0.1" "myapp.test"Run PowerShell as administrator when calling this function.
Troubleshooting Windows 11 24H2 specifically
The 24H2 update introduced no hosts file path changes but did refine DNS client caching behavior. If ipconfig /flushdns alone does not refresh resolution, run both:
Clear-DnsClientCache
ipconfig /flushdnsThen restart the DNS Client service if problems persist:
Restart-Service DnscacheSome 24H2 builds cache aggressively in the Windows Filtering Platform, a full browser restart after flushing is often necessary for Edge and Chrome.
When to use a GUI instead of manual editing
If you manage more than ten entries, switch between dev/staging profiles weekly, or onboard teammates who are uncomfortable with PowerShell, a dedicated hosts editor reduces errors. Sleezr and similar tools handle elevation, validation, backup, and DNS flush in one workflow, see the main cross-platform guide for context.
Best practices on Windows 11
- Always back up before importing blocklists
- Use
.testdomains for local dev (not.local, conflicts with mDNS on some networks) - Run
ipconfig /flushdnsafter every save, automate this in your dev scripts - Document entries with
#comments - Remove temporary overrides promptly
- Keep Windows and WSL hosts files in sync if you develop in both environments
Related guides
- Edit host file, all platforms
- Best hosts file editors for Windows
- Administrator rights
- Syntax reference
- Safety guide
- Complete reference
---
*Last tested: Windows 11 24H2, June 2026.*
Sources and further reading
Frequently Asked Questions
Where is the hosts file location on Windows 11?
The hosts file path on Windows 11 is C:\Windows\System32\drivers\etc\hosts - the same location as Windows 10. Paste that path into File Explorer or Win+R to open the folder, then open the hosts file (no extension) with an elevated editor.
How do I edit the hosts file on Windows 11?
Open Notepad as administrator, navigate to C:\Windows\System32\drivers\etc\hosts (set file filter to All Files), edit, save, then run ipconfig /flushdns in an admin terminal.
Is the Windows 11 hosts file location different from Windows 10?
No. Both use C:\Windows\System32\drivers\etc\hosts. The editing process is identical.
Can I edit the hosts file with PowerShell on Windows 11?
Yes. Open Windows Terminal or PowerShell as administrator and use notepad C:\Windows\System32\drivers\etc\hosts or Add-Content to append entries.
Why does Windows 11 block my hosts file save?
Controlled Folder Access or antivirus may block writes to System32. Add your editor to the allowed apps list in Windows Security > Ransomware protection.
How do I flush DNS on Windows 11?
Open Terminal as administrator and run: ipconfig /flushdns. Windows 11 24H2 also supports: Clear-DnsClientCache in PowerShell.
Does Windows 11 Smart App Control affect the hosts file?
Smart App Control does not block standard text editors from modifying the hosts file when run as administrator. Third-party unsigned tools may be restricted.
Related Articles
How to Edit the Hosts File on Mac (/etc/hosts) — 2026
Edit /etc/hosts on Mac with sudo nano or a GUI. Exact path, permission denied fixes, DNS flush, and when to use a hosts file manager instead of Terminal.
Sleezr Team
Hosts File: Location, Syntax and Uses (2026)
Learn what the hosts file does, where to find it on Mac, Windows and Linux, syntax examples, local dev uses and mistakes to avoid.
Sleezr Team
Can You Edit the Hosts File Without Admin Rights?
Can you edit the hosts file without administrator rights? The honest answer plus real alternatives on Windows, Mac and Linux when you cannot elevate (proxy, Docker, local DNS, SSH).
Sleezr Team
Developer tools team
How to Use Subdomains on localhost for Local Development
Use subdomains on localhost: the free *.localhost trick browsers resolve automatically, fixed subdomains via the hosts file, and wildcard subdomains with dnsmasq on Mac and Linux.
Sleezr Team
Developer tools team
Best Hosts File Editors for Windows (2026 Comparison)
Compare the best Windows hosts file editors in 2026: Sleezr, PowerToys Hosts File Editor, HostsMan, SwitchHosts, and Notepad. Feature matrix, pros/cons, and who should switch.
Sleezr Team
Developer tools team