Skip to content
Localhost Refused to Connect: How to Fix It

Localhost Refused to Connect: How to Fix It

Updated 7 min read

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.

"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

  1. Confirm the server is actually running. Look for a "listening on port…" line in its terminal. No server = guaranteed refusal. Restart it.
  2. Check the port. The URL port must match the server (localhost:3000, not :8080). A wrong port is the single most common cause.
  3. Try 127.0.0.1 directly. If http://127.0.0.1:PORT works but localhost does not, it is an IPv6/IPv4 mismatch, see below. Related: 0.0.0.0 vs 127.0.0.1.
  4. Restore the hosts entry. Ensure 127.0.0.1 localhost and ::1 localhost exist; a deleted line breaks resolution entirely.
  5. Allow the port in the firewall / antivirus. Security tools sometimes block local ports.
  6. Clear the browser DNS cache and reload in a fresh tab, chrome://net-internals/#dns.

The browser may word it differently ("This site can't be reached", "localhost refused to connect", ERR_CONNECTION_REFUSED), but it is the same error and the same checklist.

What "connection refused" actually means

Connection refused is a precise answer, not a vague failure. Your machine reached the address, and the operating system replied that no program is accepting connections on that port. That is why the fix is almost always on the server side: start it, change its port, or change the address it listens on.

Other browser errors look similar but point somewhere else:

Browser errorWhat it meansWhere to look
ERR_CONNECTION_REFUSEDNothing listens on that address and portServer stopped, wrong port, wrong bind address
ERR_CONNECTION_TIMED_OUTPackets got no answer at allA firewall or VPN dropping traffic, wrong IP
ERR_CONNECTION_RESETThe connection opened, then the server cut itApp crash on the request, proxy, HTTP/HTTPS mismatch
ERR_EMPTY_RESPONSEThe server closed without sending dataApp crashed or the wrong protocol on that port
ERR_SSL_PROTOCOL_ERRORThe browser spoke HTTPS to a plain HTTP portUse http://, or enable TLS on the dev server
ERR_NAME_NOT_RESOLVEDThe name did not resolve to an addressThe hosts entry or DNS, see [[err-name-not-resolved-mac

Operating system firewalls normally leave loopback traffic (localhost) alone, so for localhost a firewall is a less frequent cause than a stopped server. Third-party security suites and VPN clients are likelier to interfere.

Find out what is listening

Before blaming the browser, check the port from the command line:

lsof -i :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.

If a previous run is still holding the port (the "address already in use" error, EADDRINUSE), stop that process:

lsof -i :3000          # note the PID
kill <PID>

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:PORT in the browser.

You can watch the fallback happen with curl -v. A typical run (wording varies by curl version) shows the IPv6 attempt failing before the IPv4 one succeeds:

$ curl -v http://localhost:3000
*   Trying [::1]:3000...
* connect to ::1 port 3000 failed: Connection refused
*   Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000
How many times will you retype this command this month?Automate it with ToggleHosts

Browsers usually fall back the same way, so the mismatch bites hardest when the program that answers on ::1 is a different one from the program you expect. Newer Node.js versions try the next address when the first one is refused; older ones stop at the first.

Dev servers that only listen on 127.0.0.1

A server bound to 127.0.0.1 accepts connections from the same machine only. That is fine for a browser on the same computer, and a dead end for a container, a phone or a virtual machine. Common defaults:

ToolDefault addressTo accept outside connections
Vitelocalhostvite --host
Django runserver127.0.0.1:8000python manage.py runserver 0.0.0.0:8000
Flask127.0.0.1:5000flask run --host=0.0.0.0
Laravel artisan serve127.0.0.1:8000php artisan serve --host=0.0.0.0
Node server.listen(port)all interfacesserver.listen(port, '127.0.0.1') restricts it
Python http.serverall interfaces--bind 127.0.0.1 restricts it

Binding to 0.0.0.0 exposes the server to your whole network, so use it on a trusted network or behind a firewall. Background in 0.0.0.0 vs 127.0.0.1.

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 localhost

On 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:3000 on the host is refused.
  • The app inside the container must listen on 0.0.0.0, not on the container's own 127.0.0.1. Publishing the port does not help if the app only accepts connections from inside the container. For Flask, that means flask run --host=0.0.0.0.

Proxies, VPNs and security software

  • A system or corporate proxy can intercept localhost requests. Exclude local addresses from it, and for command-line tools set NO_PROXY=localhost,127.0.0.1,::1.
  • VPN clients and endpoint security suites sometimes filter local ports. Disconnect or pause them for a minute to test.
  • After a restart, services such as Apache or a dev server are not running until you start them again, unless you set them to launch at login.

Verify the fix

curl -I http://127.0.0.1:3000
curl -I http://localhost:3000

If 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 ToggleHosts keeps the core localhost entries intact, lets you toggle custom domains safely, and flushes DNS automatically, so localhost keeps answering. To pick a hosts manager, the editor comparisons for Windows, Mac and Linux put the options side by side.

_Last tested: June 2026 on Windows 11, macOS 26 and Ubuntu 24.04._

Sources and further reading

Frequently Asked Questions

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.

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.

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.

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.

Related Articles

© 2026 ToggleHosts · All rights reserved[email protected]