How to Edit the Hosts File on Windows 11 (2026)
Three methods to edit the Windows 11 hosts file: Notepad as admin, PowerShell, and VS Code. Includes UAC tips, DNS flush, and troubleshooting for 24H2.
Locahl Team
Table of Contents
- Hosts file location on Windows 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
Windows 11 changed a lot about the desktop experience β but the hosts file location and core editing process remain the same as Windows 10. What Windows 11 adds is a better Terminal, updated UAC dialogs, and new security features that occasionally interfere with System32 edits.
This guide covers three methods to edit the hosts file on Windows 11, plus troubleshooting specific to the 24H2 update.
See also: Main cross-platform guide Β· Windows 10 guide
Hosts file location on Windows 11
C:\Windows\System32\drivers\etc\hostsUnchanged since Windows XP. No extension. Requires administrator write access.
Method 1: Notepad as administrator (recommended for beginners)
This method works identically on Windows 10 and 11.
1. Press Windows key, type Notepad 2. Right-click Notepad β Run as administrator 3. Click Yes on the UAC prompt (Windows 11 shows a modern dialog with app name and publisher) 4. File β Open 5. Navigate to C:\Windows\System32\drivers\etc 6. Change file type to **All Files (*.*) 7. Select hosts, click Open** 8. Add your entries:
127.0.0.1 myproject.test
127.0.0.1 api.myproject.test9. Ctrl+S to save 10. Flush DNS (see below)
Method 2: PowerShell / Windows Terminal (recommended for developers)
Windows 11 ships with Windows Terminal pre-installed β use it for faster workflows.
Open hosts file directly
1. Press Windows key, type Terminal 2. Right-click Terminal β Run as administrator 3. Run:
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:
1. Right-click Visual Studio Code in Start β Run as administrator 2. File β Open File 3. Paste path: C:\Windows\System32\drivers\etc\hosts 4. Edit with full editor features (search, replace, Git-style diff if you keep a backup) 5. Ctrl+S to save 6. Flush DNS
Tip: 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: 1. Settings β Privacy & security β Windows Security β Virus & threat protection 2. Manage ransomware protection 3. Under Allow an app through Controlled folder access, add Notepad, VS Code, or Terminal
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. Locahl 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
- Windows 10 guide
- Administrator rights
- Syntax reference
- Safety guide
- Complete reference
---
*Last tested: Windows 11 24H2 β June 2026.*
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"The PowerShell method is my new default β much faster than navigating Notepad dialogs every time."
June 4, 2026
"Finally got Windows 11 hosts editing working. The All Files filter tip was essential."
June 6, 2026
"Good coverage of three methods. VS Code section saved me from Notepad formatting issues."
June 10, 2026
Frequently Asked Questions
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 Windows 10 (2026)
Edit the Windows 10 hosts file step by step: Notepad as administrator, file location, UAC, save errors, DNS flush, and troubleshooting access denied.
Locahl Team
Edit the hosts file on Mac: Terminal vs GUI (2026)
How to edit /etc/hosts on macOS without errors? Terminal (sudo nano) vs GUI comparison. Fix permission denied and DNS cache issues in 2 minutes.
Locahl 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.
Locahl Team
How to Edit the Host File on Windows, Mac and Linux (2026)
Edit the host file on Windows, macOS and Linux: file location, admin rights, syntax, DNS flush, and troubleshooting when changes do not apply.
Locahl Team
How to Edit the Hosts File on Linux (2026)
Edit /etc/hosts on Linux with nano or vim: permissions, syntax, DNS flush on systemd and legacy systems, and troubleshooting for developers.
Locahl Team