Sleezr
Buy Sleezr
hosts fileWindows 11PowerShelltutoriallocal development

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.

S

Sleezr Team

·Updated ·8 min read
Hosts File Location Windows 11: C:\Windows\System32\drivers\etc\hosts

Hosts file location on Windows 11 (same as Windows 10):

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

Paste 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 10Windows 11
Hosts pathC:\Windows\System32\drivers\etc\hostsSame
Default editorNotepad as adminNotepad or Windows Terminal as admin
DNS flushipconfig /flushdnsSame + Clear-DnsClientCache in PowerShell
Extra gotchasDefender rarely blocksControlled 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:

TEXT
C:\Windows\System32\drivers\etc\hosts
  • Folder: C:\Windows\System32\drivers\etc
  • File: hosts (no .txt extension)
  • Fast open: Win+R → paste the folder path → Enter → open hosts with 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:

1
Press the Windows key, type Notepad, right-click it, and select Run as administrator.
2
Choose File → Open, browse to C:\Windows\System32\drivers\etc, set the filter to All Files, and open hosts.
3
Add a new line with the IP address, a space, then the domain, for example 127.0.0.1 mysite.test.
4
Press Ctrl+S to save (reopen as administrator if you see "Access denied").
5
Open Windows Terminal as administrator and run ipconfig /flushdns.

The PowerShell method and Windows 11 security notes are below.

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. 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 .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.*

Sources and further reading

Share this article

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

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.

S

Sleezr Team

4 min read
hosts fileadmin rightspermissions

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).

S

Sleezr Team

Developer tools team

4 min read
localhostsubdomainslocal development

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.

S

Sleezr Team

Developer tools team

10 min read
hosts fileWindowseditors

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.

S

Sleezr Team

Developer tools team