127.0.0.1 localhost loopback guide showing IPv4 and IPv6 addresses, common ports, local development uses, network distinctions, and troubleshooting methods.

Every computer running TCP/IP believes 127.0.0.1 means itself. Not the router, not the network card, not the machine next to it. Send a packet there and the kernel turns it around before it ever reaches hardware. That single trick underpins local development, service testing, and a fair number of confusing error messages.

The address that never leaves the building

The whole 127.0.0.0/8 block is reserved for loopback, which is over sixteen million addresses set aside for one machine’s internal chatter. Almost nobody uses more than the first one. You can prove the range is live: ping 127.9.9.9 on Linux and it answers, because the kernel treats anything starting with 127 the same way. Windows is fussier and generally only honours the first address.

The name localhost is not magic either. It resolves through your hosts file, a plain text list that maps names to addresses before DNS gets a say. On Linux and macOS it sits at /etc/hosts; on Windows, under System32\drivers\etc. Open it and the first uncommented line is almost always the mapping from localhost to 127.0.0.1.

Localhost address builder and port reference

Three names, one destination

127.0.0.1

The literal IPv4 loopback. Unambiguous, resolves instantly, works even when name resolution is broken.

localhost

A hostname that depends on your hosts file. Convenient, but it can be redirected or, on some systems, prefer IPv6.

::1

The IPv6 equivalent. Written with brackets in URLs. A service bound only to IPv4 will refuse it.

0.0.0.0

Not loopback at all. It means every interface, which is how you expose a local server to the rest of the network.

That last distinction trips up more people than the others combined. A development server bound to 127.0.0.1 is invisible to your phone, your colleague, and the machine in the next room. Rebind it to 0.0.0.0 and suddenly anything on the same subnet can reach it, at which point your router’s LAN addressing becomes relevant. Most home networks hand out addresses behind the default 192.168.1.1 gateway, and the boundaries of that neighbourhood are set by a standard class C mask.

What people actually use it for

  • Running a web app locally before it goes anywhere near a server
  • Pointing a database client at an engine on the same machine, usually via 3306 or 5432
  • Blocking domains by mapping them to 127.0.0.1 in the hosts file, so requests die instantly
  • Confirming the TCP stack is alive when a network refuses to cooperate
  • Tunnelling through SSH, where a remote port is stitched onto a local loopback port

Blocking sites the old-fashioned way

Add a line like 127.0.0.1 example-site.tld and the browser will try to fetch that domain from your own machine, find nothing listening, and fail. It is crude but effective, and it survives reboots. The downside is that a failed connection can hang for a moment; some people use 0.0.0.0 instead for a faster rejection.

When ping 127.0.0.1 fails

If loopback does not respond, the problem is not your network. It is the TCP/IP stack itself, a mangled hosts file, or a firewall rule that somebody applied far too aggressively. On Windows, resetting the stack with netsh int ip reset fixes most of these. On Linux, check that the lo interface is actually up with ip link show lo.

Ports you will meet on loopback

PortUsuallyNotes
3000Node, React, RailsIncrements to 3001 when taken
5173ViteModern front-end default
8000Django, python http.serverCommon teaching default
8080Tomcat, proxiesThe unprivileged stand-in for 80
7860Gradio appsMachine learning demo interfaces
49152+EphemeralAssigned automatically, never fixed

Ports below 1024 need administrator rights to bind, which is exactly why so much local tooling settles on four-digit numbers instead. Anything above 49151 is temporary by design — the reason a stray listener on port 49342 vanishes after a restart while a purpose-built tool holds 7860 for its web interface every single time.

Common failures and what they mean

Connection refused

Nothing is listening on that port. The server crashed, never started, or picked a different number than you expected. Read the startup log rather than guessing.

Address already in use

Another process got there first, sometimes a zombie copy of the same app. Find the PID, end it, then start again. A socket lingering in TIME_WAIT will also produce this and clears on its own within a couple of minutes. The same pattern shows up with editor debug sessions that refuse to let go of their inspector port.

It works in the terminal but not the browser

Usually a scheme problem. The browser upgraded your request to HTTPS while the server only speaks plain HTTP. Type the address with http:// spelled out, and clear the HSTS entry if the browser has cached one.

Works for you, not for anyone else

Expected. Loopback is private per machine. Sharing requires binding to a real interface and, in many cases, a firewall exception. If the other device sits on a completely different range — say a corporate segment rather than a home one — the routing question is a separate matter, and the notes on public blocks like 20.0.0.1 explain why not every numeric address is yours to use. For a slower service that stubbornly holds its socket open, the port 57573 walkthrough covers the cleanup steps.

FAQ

Why does my computer answer to 127.0.0.1 at all?

The operating system creates a virtual loopback interface at boot. It exists so software can use network protocols to talk to itself without any hardware involved.

Should localhost or 127.0.0.1 be used in config files?

Use the numeric form when you need certainty. It skips name resolution and cannot accidentally resolve to the IPv6 address instead.

Can someone attack me through 127.0.0.1?

Not remotely. It is only reachable from software already running on your machine, so the risk comes from what you have installed, not from outside.

Is 127.0.0.1 the same as my router address?

No. Your router sits on a private LAN address such as 192.168.1.1. Loopback never reaches the router or any other device.

How do I stop a program using loopback?

Identify the process with a port listing command, then end that process. Firewall rules on loopback tend to break local tools rather than help.

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.