Locahl
Buy Locahl
localhosttroubleshootingERR_CONNECTION_REFUSEDportshosts file

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.

L

Locahl Team

Β·4 min read

"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: 127.0.0.1 vs localhost. 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.

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:

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

When the hosts file is the culprit

A removed or commented localhost line breaks resolution system-wide. Restore both entries:

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

Verify the fix

BASH
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 Locahl 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

Also readFix "this site can't be reached" on localhost
Also read127.0.0.1 vs localhost explained
Share this article
Available on Windows, macOS & Linux

Ready to simplify your workflow?

Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.

  • Intuitive visual interface
  • Automatic DNS flush
  • Multi-environment management
  • Automatic backups
  • JSON Import/Export
Buy Locahl β€” $11.99One-time payment, no subscription

Reader Reviews

4.7β˜…(3 reviews)
Hugo R.
β˜…β˜…β˜…β˜…β˜…

"My server bound to IPv4 only β€” switching the URL to 127.0.0.1 worked immediately. The checklist nailed it."

June 21, 2026

Mei L.
β˜…β˜…β˜…β˜…β˜…

"The XAMPP port section was exactly my problem. Apache was not running on 80."

June 20, 2026

Sven A.
β˜…β˜…β˜…β˜…β˜…

"Clear and ordered. A note on Docker port mapping would round it out."

June 19, 2026

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

3 min read
localhosttroubleshootingERR_CONNECTION_REFUSED

Fix "This site can’t be reached" on localhost

Fix "This site can’t be reached" / ERR_CONNECTION_REFUSED on localhost: check the server is running, the right port, IPv6 vs IPv4, the hosts file and firewall.

L

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

L

Locahl Team

Developer tools team

4 min read
hosts filetroubleshootingDNS

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

L

Locahl Team

Developer tools team

2 min read
localhost127.0.0.1DNS

127.0.0.1 vs localhost: What’s the Difference?

127.0.0.1 vs localhost explained: both point to your machine, but they differ in DNS resolution, IPv6, and hosts file behavior. When to use each, with examples.

L

Locahl Team

Developer tools team

3 min read
DNSChrometroubleshooting

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.

L

Locahl Team

Developer tools team