Locahl
Get Locahl
hosts fileWindows 11PowerShelltutoriallocal development

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.

L

Locahl Team

Β·Updated Β·7 min read

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

TEXT
C:\Windows\System32\drivers\etc\hosts

Unchanged since Windows XP. No extension. Requires administrator write access.

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:

TEXT
127.0.0.1    myproject.test
127.0.0.1    api.myproject.test

9. Ctrl+S to save 10. Flush DNS (see below)

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:

POWERSHELL
notepad C:\Windows\System32\drivers\etc\hosts

Notepad opens with the file loaded. Edit, save, close.

Append an entry without opening an editor

POWERSHELL
Add-Content -Path C:\Windows\System32\drivers\etc\hosts -Value "127.0.0.1    newsite.test"

View current hosts file content

POWERSHELL
Get-Content C:\Windows\System32\drivers\etc\hosts

Flush DNS from the same terminal

POWERSHELL
ipconfig /flushdns
# Or on Windows 11 24H2:
Clear-DnsClientCache

Back up before editing

POWERSHELL
Copy-Item C:\Windows\System32\drivers\etc\hosts C:\Windows\System32\drivers\etc\hosts.backup

Method 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:

POWERSHELL
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:

CMD
ipconfig /flushdns

Or in PowerShell:

POWERSHELL
Clear-DnsClientCache

Then clear browser cache if needed:

  • Chrome/Edge: chrome://net-internals/#dns β†’ Clear host cache
  • Firefox: about:networking#dns β†’ Clear DNS Cache

Verify changes

POWERSHELL
ping myproject.test
nslookup myproject.test

Both 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:

POWERSHELL
Copy-Item C:\Windows\System32\drivers\etc\hosts $env:USERPROFILE\Documents\hosts.backup

Restore after update:

POWERSHELL
Copy-Item $env:USERPROFILE\Documents\hosts.backup C:\Windows\System32\drivers\etc\hosts

DNS 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

MethodBest forProsCons
Notepad (admin)Beginners, one-off editsSimple, always availableNo syntax highlighting
PowerShell/TerminalDevelopers, scriptsFast, scriptable, backup commandsRequires terminal comfort
VS Code (admin)Large files, many entriesSearch, replace, extensionsMust launch as admin

Example entries for common Windows 11 dev setups

Local WordPress/Laravel:

TEXT
127.0.0.1    mysite.test
127.0.0.1    www.mysite.test

Block distractions:

TEXT
0.0.0.0    twitter.com
0.0.0.0    www.twitter.com

See Block a website with the hosts file.

Staging server override:

TEXT
203.0.113.50    client.com
203.0.113.50    www.client.com

WSL 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:

BASH
# Inside WSL β€” edit the Linux hosts file
sudo nano /etc/hosts
# Add the same entries as Windows

Alternatively, 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:

POWERSHELL
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:

POWERSHELL
Clear-DnsClientCache
ipconfig /flushdns

Then restart the DNS Client service if problems persist:

POWERSHELL
Restart-Service Dnscache

Some 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 .test domains for local dev (not .local β€” conflicts with mDNS on some networks)
  • Run ipconfig /flushdns after 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

---

*Last tested: Windows 11 24H2 β€” June 2026.*

Share this article
Available on Windows, macOS & Linux

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
Get Locahl β€” $5.99One-time payment, no subscription

Reader Reviews

4.7β˜…(3 reviews)
Alex R.
β˜…β˜…β˜…β˜…β˜…

"The PowerShell method is my new default β€” much faster than navigating Notepad dialogs every time."

June 4, 2026

Nina V.
β˜…β˜…β˜…β˜…β˜…

"Finally got Windows 11 hosts editing working. The All Files filter tip was essential."

June 6, 2026

Jason M.
β˜…β˜…β˜…β˜…β˜…

"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

7 min read
hosts fileWindows 10tutorial

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.

L

Locahl Team

6 min read
hosts filemacOStutorial

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.

L

Locahl Team

6 min read
hosts fileDNSlocal development

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.

L

Locahl Team

7 min read
hosts fileLinux/etc/hosts

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.

L

Locahl Team