Locahl
Buy Locahl
localhosttroubleshootingERR_CONNECTION_REFUSEDhosts fileports

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

·2 min read

"This site can’t be reached" on localhost almost always means nothing is listening where the browser is connecting. The common causes are: the 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 hosts entry for localhost is missing, or a firewall blocked the port. Work through the checklist below in order.

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

1. Confirm the server is running. Check its terminal for a "listening on port…" message; restart it if needed. 2. Verify the port. Make sure the URL port matches the server (e.g. localhost:3000, not :8080). 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 — bind the server to 0.0.0.0/:: or use 127.0.0.1. See 127.0.0.1 vs localhost. 4. Check the hosts file. Ensure 127.0.0.1 localhost and ::1 localhost exist; restore them if missing. 5. Inspect the firewall / antivirus. Allow the port for local connections. 6. Clear the browser DNS cache and reload — chrome://net-internals/#dns.

Diagnose what is listening

BASH
# macOS / Linux
lsof -i :3000
# Windows
netstat -ano | findstr :3000

If nothing shows up, the server is not listening on that port — fix the app, not the browser.

The IPv6 vs IPv4 trap

Modern systems often resolve localhost to IPv6 ::1 first. If your server listens only on IPv4 127.0.0.1, the browser gets connection refused. Either bind to all interfaces (see 0.0.0.0 vs 127.0.0.1) or connect to 127.0.0.1 explicitly.

When the hosts file is the culprit

A removed or edited localhost line breaks resolution entirely. Restore:

TEXT
127.0.0.1 localhost
::1 localhost

On Mac, see localhost not working on Mac and hosts file not working.

Avoid future breakage

Accidental edits to the localhost line are a frequent cause. A hosts manager like Locahl keeps core entries intact, lets you toggle custom domains safely, and flushes DNS automatically, so localhost keeps working.

_Last tested: June 2026 on Windows, macOS and Linux._

Also read127.0.0.1 vs localhost explained
Also readFix localhost not working on Mac
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$5.99One-time payment, no subscription

Reader Reviews

4.7(3 reviews)
Derek H.

"It was the IPv6 vs IPv4 binding. Connecting to 127.0.0.1 instead of localhost fixed it instantly."

June 12, 2026

Yuki S.

"The ordered checklist found my problem fast — the server was bound to the wrong port."

June 10, 2026

Olga P.

"Very practical. A note on antivirus blocking ports would help."

June 8, 2026

Frequently Asked Questions

Why does localhost say "This site can’t be reached"?

Usually no server is listening on that port, the port is wrong, the server bound to IPv6 only (or IPv4 only), or the hosts file entry for localhost is missing.

How do I fix ERR_CONNECTION_REFUSED on localhost?

Confirm the server is running and on the expected port, try 127.0.0.1 instead of localhost, restore the localhost hosts entry, and check the firewall.

Why does 127.0.0.1 work but localhost does not?

localhost may resolve to IPv6 ::1 while the server listens only on IPv4 127.0.0.1. Bind the server to all interfaces or use 127.0.0.1.

Can the hosts file cause this error?

Yes. If the 127.0.0.1 localhost line was removed, localhost will not resolve and the browser cannot connect.

Related Articles

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

2 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

2 min read
localhost127.0.0.1DNS

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.

L

Locahl Team

Developer tools team

2 min read
WordPressredirectmigration

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.

L

Locahl Team

Developer tools team

8 min read
hosts fileadministratorpermissions

How to Edit the Hosts File as Administrator (2026)

Why the hosts file requires admin rights on Windows, Mac and Linux. Fix access denied, permission errors, and UAC issues on every platform.

L

Locahl Team