Localhost Refused to Connect: How to Fix It
Fix "localhost refused to connect" (ERR_CONNECTION_REFUSED) in Chrome, on Windows, Mac, XAMPP and VS Code: check the server, the port, IPv6 vs IPv4, hosts file and firewall.
Sleezr Team

Table of Contents
- Fix "localhost refused to connect", checklist
- Find out what is listening
- The IPv6 vs IPv4 trap (127.0.0.1 works, localhost doesn't)
- When the hosts file is the culprit
- Fixes by environment
- Chrome (and other browsers)
- Windows 10 / 11
- XAMPP / MAMP / WAMP
- VS Code / Node / Vite dev servers
- Docker
- Verify the fix
- Avoid future breakage
- Sources and further reading
"Localhost refused to connect" (ERR_CONNECTION_REFUSED) almost always means nothing is listening where the browser is connecting. The usual causes: the local server is not running, it is on a different port, it bound to IPv6 (::1) while you reached IPv4 (127.0.0.1) or vice versa, the localhost hosts entry is missing, or a firewall blocked the port. Work through the checklist below in order and you will find it fast.
Fix "localhost refused to connect", checklist
localhost:3000, not :8080). A wrong port is the single most common cause.http://127.0.0.1:PORT works but localhost does not, it is an IPv6/IPv4 mismatch, see below. Related: 127.0.0.1 vs localhost.127.0.0.1 localhost and ::1 localhost exist; a deleted line breaks resolution entirely.chrome://net-internals/#dns.This shares causes with the "this site can't be reached" on localhost error, same checklist, different wording shown by the browser.
Find out what is listening
Before blaming the browser, check the port from the command line:
# macOS / Linux
lsof -i :3000
# Windows (Command Prompt)
netstat -ano | findstr :3000- Nothing returned → the server is not listening on that port. Fix the app, not the browser.
- A different PID than expected → another process grabbed the port; stop it or change your port.
The IPv6 vs IPv4 trap (127.0.0.1 works, localhost doesn't)
Modern systems resolve localhost to IPv6 ::1 first. If your dev server listens only on IPv4 127.0.0.1, the IPv6 connection is refused and the browser reports "localhost refused to connect", even though http://127.0.0.1:PORT works.
Two fixes:
- Bind the server to all interfaces:
0.0.0.0(IPv4) or::(dual stack). See 0.0.0.0 vs 127.0.0.1. - Or just use
http://127.0.0.1:PORTin the browser.
When the hosts file is the culprit
A removed or commented localhost line breaks resolution system-wide. Restore both entries:
127.0.0.1 localhost
::1 localhostOn Mac, see localhost not working on Mac. To edit the file safely, see how to edit the hosts file.
Fixes by environment
Chrome (and other browsers)
The error text comes from the browser, but the cause is the server/port/DNS, not Chrome itself. Still, clear Chrome's host cache (chrome://net-internals/#dns) and test in Incognito to rule out an extension or stale cache.
Windows 10 / 11
- Run the dev server in an elevated terminal if it needs a privileged port (< 1024).
- Check Windows Defender Firewall is not blocking the port.
- Confirm no proxy is set: Settings → Network & internet → Proxy.
XAMPP / MAMP / WAMP
- Start Apache (and MySQL) in the control panel, a stopped service refuses every connection.
- Port 80/443 is often taken by Skype, IIS, or VPN software. Change Apache's port (e.g. to 8080) or stop the conflicting app.
VS Code / Node / Vite dev servers
- Read the actual URL the server prints, frameworks pick a free port (3000, 5173, 8000…) and it may differ from what you typed.
- If you run inside WSL2 or a container, the port must be forwarded to the host.
Docker
- The container port must be published to the host:
-p 3000:3000. Without it,localhost:3000on the host is refused.
Verify the fix
curl -I http://127.0.0.1:3000
curl -I http://localhost:3000If the IP works but the name fails, return to the IPv6/hosts steps. If both fail, the server is not listening, fix the process first.
Avoid future breakage
Accidental edits to the localhost line are a frequent, hard-to-spot cause. A hosts manager like Sleezr keeps the core localhost entries intact, lets you toggle custom domains safely, and flushes DNS automatically, so localhost keeps answering.
_Last tested: June 2026 on Windows 11, macOS 26 and Ubuntu 24.04._
Sources and further reading
- localhost and the loopback address (Wikipedia)
- The hosts file explained (Wikipedia)
- How DNS works (Cloudflare Learning)
Frequently Asked Questions
Why does localhost refuse to connect?
In almost all cases nothing is listening where the browser connects: the server is not running, it is on a different port, it bound to IPv6 only (or IPv4 only), the localhost hosts entry is missing, or a firewall blocked the port.
How do I fix ERR_CONNECTION_REFUSED on localhost?
Confirm the server is running and on the expected port, try http://127.0.0.1:PORT instead of localhost, restore the 127.0.0.1 localhost hosts line, allow the port in the firewall, and clear the browser DNS cache.
Why does 127.0.0.1 work but localhost refuses to connect?
localhost often resolves to IPv6 ::1 first. If your server listens only on IPv4 127.0.0.1, the IPv6 attempt is refused. Bind the server to all interfaces (0.0.0.0 / ::) or use 127.0.0.1 in the URL.
Why does localhost refuse to connect in XAMPP or MAMP?
The Apache/MySQL service is usually stopped or another app holds port 80/443 (often Skype, IIS or VPN software). Start the service in the control panel and change the port if it is taken.
Can the hosts file cause "localhost refused to connect"?
Yes. If the 127.0.0.1 localhost line was deleted or commented out, localhost will not resolve and the browser cannot connect. Restore 127.0.0.1 localhost and ::1 localhost.
Related Articles
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.
Sleezr Team
Developer tools team
/etc/hosts Not Working? Fixes for Windows, Mac & Linux
The hosts file is ignored or /etc/hosts changes do not take effect? Fix it on Windows, Mac and Linux: flush DNS, check syntax, IPv6, line endings, resolver caches and save permissions.
Sleezr Team
Developer tools team
Fix DNS_PROBE_FINISHED_NXDOMAIN (2026)
Fix DNS_PROBE_FINISHED_NXDOMAIN in Chrome and Edge: flush DNS, check the hosts file, reset DNS servers and clear the browser cache. Step-by-step solutions.
Sleezr Team
Developer tools team
What Is localhost? A Clear Explanation
What is localhost? It is the hostname for your own computer, resolving to 127.0.0.1 (or ::1) via the hosts file. How it works, why it matters, and common issues.
Sleezr Team
Developer tools team
Fix WordPress Redirecting to the Live Site
WordPress redirects to the live site when testing on a new server because the URL is hard-coded in the database. Fix it with the hosts file, no DB edits needed.
Sleezr Team
Developer tools team