localhost
or 127.0.0.1
stopped working after a Windows 11 update, fix it in this order:
- Verify the app is actually listening on 127.0.0.1 or ::1 and the expected port.
- Reset winsock/DNS, clear NRPT and proxies, and re-add loopback exemptions for Store apps.
- Repair the
hosts
file, re-enablelocalhost
mapping, and flush caches. - Check Windows Defender Firewall rules (private/public) and disable conflicting port proxies/VPN DNS hijacks.
- For WSL/Hyper-V/IIS Express, rebind to the correct interface or recreate dev-certs and URLACLs.
Audience: US • EU • UK • AU • IN developers, SRE/DevOps, AppSec, and IT helpdesks dealing with broken local dev servers after Patch Tuesday.
Symptoms You’ll See
ERR_CONNECTION_REFUSED
,Hmmm… can’t reach this page
, orcurl: (7) Failed to connect
tolocalhost
.ping localhost
resolves to IPv6::1
but your app only listens on127.0.0.1
(or vice-versa).- Port suddenly “in use” by a different PID after update (IIS Express or a security agent grabbing :80/:443).
- Only UWP/Store apps (Edge WebView2, Teams, Mail) can’t hit
localhost
due to loopback isolation.
Step 1 — Confirm Something Is Actually Listening
# PowerShell (run as Administrator) Get-NetTCPConnection -State Listen | Sort-Object -Property LocalPort | Select-Object -First 30 ` | Format-Table LocalAddress,LocalPort,OwningProcess # Classic netstat -ano | findstr LISTENING # Map PID → process tasklist /fi "PID eq <PID>"
If your app is bound to 0.0.0.0:3000
it should accept localhost:3000
. If it’s bound only to 192.168.x.x
, update the bind address to 127.0.0.1
or add a second listener.
Step 2 — Quick Health Resets (Safe, Reversible)
# Run in elevated PowerShell ipconfig /flushdns netsh winsock reset netsh int ip reset # Remove stale Name Resolution Policy Table (NRPT) entries that can hijack localhost Get-DnsClientNrptRule | Remove-DnsClientNrptRule -Force # Disable system-wide proxy if accidentally enabled by VPN/update netsh winhttp show proxy netsh winhttp reset proxy
Step 3 — Repair the hosts
File
Updates or security tools sometimes comment out localhost
. Ensure these lines exist (and aren’t duplicated):
# C:\Windows\System32\drivers\etc\hosts (edit as Administrator) 127.0.0.1 localhost ::1 localhost
Step 4 — Re-enable Loopback for Store/UWP Apps
Windows app container isolation can block WebView/Store apps (e.g., Edge WebView2, Teams) from hitting localhost
. Exempt your app package family name (PFN) or exempt all for dev boxes:
# List packages to find PFN PowerShell> Get-AppxPackage | Select Name, PackageFamilyName # Exempt a specific PFN CheckNetIsolation LoopbackExempt -a -n=Microsoft.WindowsTerminal_8wekyb3d8bbwe # As last resort during active development (review later!) CheckNetIsolation LoopbackExempt -a -p=all # Verify CheckNetIsolation LoopbackExempt -s
Step 5 — Fix Windows Defender Firewall & Profile Mismatch
- Updates can flip your network to Public. Your inbound rule may be Private-only.
- Create (or edit) an allow rule for your port on both Private and Public while you test.
# Example: open 3000 TCP on both profiles (dev only; remove when done) New-NetFirewallRule -DisplayName "Dev-Local-3000" -Direction Inbound -Protocol TCP -LocalPort 3000 -Action Allow -Profile Private,Public
Step 6 — Kill Conflicting Port Proxies & Services
Some VPNs or prior IIS/HTTP.SYS config leave port proxies behind.
# Show any portproxy rules (remove unexpected ones) netsh interface portproxy show all netsh interface portproxy reset # IIS/HTTP.SYS URL reservations (for self-hosted Kestrel, etc.) netsh http show urlacl # Example: remove a stale reservation netsh http delete urlacl url=http://+:3000/
Also check common “hijackers”: security agents, Docker Desktop, WSLg, IIS Express. If :80
/:443
are taken by System
(PID 4), HTTP.SYS is bound—use a different port or adjust URLACLs.
Step 7 — WSL / Hyper-V / IIS Express Specifics
- WSL: If you hit
localhost
from Windows to a WSL service, ensure the app binds to0.0.0.0
in Linux or expose viawsl.exe --shutdown
then restart. Recreate dev certs if you serve HTTPS from WSL. - Hyper-V/Dev VMs: NAT switch changes post-update; confirm port-forward rules in
Get-NetNatStaticMapping
. - IIS Express: Rebuild
applicationhost.config
, or re-create dev certs:dotnet dev-certs https --clean dotnet dev-certs https --trust
Step 8 — IPv4 vs IPv6 Preference (Temporary Toggle)
If your app only listens on IPv4 and Windows prefers IPv6 ::1
for localhost
, either bind dual-stack or temporarily prefer IPv4:
# Prefer IPv4 over IPv6 (requires reboot) — TEMPORARY on dev boxes only reg add "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" /v DisabledComponents /t REG_DWORD /d 0x20 /f
Revert later by deleting DisabledComponents
or setting to 0
.
Step 9 — Clean Browser/Cert State
- Clear HSTS for
localhost
(Chrome:chrome://net-internals/#hsts
) if you toggled HTTP/HTTPS. - Ensure trusted dev certificate is present (
certmgr.msc
→ Trusted Root Certification Authorities). - Test with
curl -v http://127.0.0.1:PORT
andcurl -v http://localhost:PORT
(compare DNS/SSL behavior).
One-Click Script (Paste into Elevated PowerShell)
Review before running. This performs safe resets, restores hosts
, clears NRPT/proxy, and prints listeners.
$hosts = "$env:SystemRoot\System32\drivers\etc\hosts" $bk = "$hosts.bak.$((Get-Date).ToString('yyyyMMddHHmmss'))" Copy-Item $hosts $bk -Force # Ensure localhost mappings exist exactly once $lines = Get-Content $hosts | Where-Object {$_ -notmatch '^\s*#'} $ipv4 = '127.0.0.1 localhost' $ipv6 = '::1 localhost' $filtered = ($lines | Where-Object {$_ -notmatch '\slocalhost(\s|$)'} ) $filtered += $ipv4, $ipv6 $filtered | Set-Content -Path $hosts -Encoding ASCII ipconfig /flushdns | Out-Null netsh winsock reset | Out-Null netsh int ip reset | Out-Null if (Get-Command Get-DnsClientNrptRule -ErrorAction SilentlyContinue) { Get-DnsClientNrptRule | Remove-DnsClientNrptRule -Force 2>$null } netsh winhttp reset proxy | Out-Null Write-Host "`nActive listeners:" -ForegroundColor Cyan Get-NetTCPConnection -State Listen | Sort-Object LocalPort | ft -AutoSize LocalAddress,LocalPort,OwningProcess
Still Broken? Quick Triage Matrix
Symptom | Likely Cause | Fix |
---|---|---|
Only Store apps can’t reach localhost | Loopback isolation | CheckNetIsolation LoopbackExempt -a -p=all (dev) or per-PFN |
Ping localhost resolves to ::1 but app listens on 127.0.0.1 | IPv6 preference mismatch | Bind dual-stack or temporarily prefer IPv4 |
Port in use by PID 4 (System) | HTTP.SYS URL reservation | netsh http show urlacl and delete or change app port |
Works after VPN disconnect | VPN NRPT/proxy rewrite | Reset NRPT/proxy; add split-tunnel exceptions |
Random ECONNREFUSED spikes |
AV/EDR HTTPS inspection or port hijack | Exclude dev ports/certs; restart agent or change ports |
Security & Dev Essentials (sponsored)
Disclosure: We may earn a commission if you buy via these links. This supports independent research.
Windows 11, localhost, 127.0.0.1, ::1, winsock, NRPT, hosts file, firewall, URLACL, HTTP.SYS, IIS Express, WSL, Hyper-V, VPN, split tunnel, DevOps, SRE, AppSec, enterprise IT support.
#Windows11 #Localhost #Developers #DevOps #SRE #AppSec #WSL #IISExpress #Winsock #Firewall #VPN #NRPT #Loopback #Troubleshooting #EnterpriseIT #US #EU #UK #Australia #India
Educational and defensive guidance only. Validate commands in a non-production environment before applying to enterprise fleets.
Comments
Post a Comment