Hosts File Location on Windows 11

Hosts File Location on Windows 11

Updated 9 min read

C:\Windows\System32\drivers\etc\hosts — open and edit it as admin on Windows 11 (and 10), fix Access Denied, then flush DNS.

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

C:\Windows\System32\drivers\etc\hosts
How many times will you retype this command this month?Automate it with ToggleHosts

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.

Next: edit without admin rights · flush DNS on Windows

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:

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.

Can you edit the Windows 11 hosts file without admin rights?

You cannot save the system hosts file as a standard user. Windows protects it because every application can rely on its mappings. If you cannot elevate, do not weaken the file permissions or disable UAC. Use an approved per-application proxy, a Docker --add-host mapping, or another option in the guide to hosts mappings without admin rights.

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:
127.0.0.1 myproject.test
127.0.0.1 api.myproject.test
  1. Ctrl+S to save
  2. 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:
notepad C:\Windows\System32\drivers\etc\hosts

Notepad 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\hosts

Flush DNS from the same terminal

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

Back up before editing

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:

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 /flushdns

Or in 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

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:

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

Restore after update:

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:

127.0.0.1 mysite.test
127.0.0.1 www.mysite.test

Block distractions:

0.0.0.0 twitter.com
0.0.0.0 www.twitter.com

See Block a website with the hosts file.

Staging server override:

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:

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

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 /flushdns

Then restart the DNS Client service if problems persist:

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. ToggleHosts and similar tools handle elevation, validation, backup, and DNS flush in one workflow, see the main cross-platform guide for context.

Prefer a visual walkthrough without Notepad as administrator?

How to Edit the Hosts File on Windows 11 (No Notepad Admin, No Access Denied) · @ToggleHosts_app

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

Frequently Asked Questions

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.

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.

No. Both use C:\Windows\System32\drivers\etc\hosts. The editing process is identical.

Yes. Open Windows Terminal or PowerShell as administrator and use notepad C:\Windows\System32\drivers\etc\hosts or Add-Content to append entries.

Related Articles