loopback
← All posts

Lab / Networking / Linux / FreeBSD

What Is Loopback? Localhost and 127.0.0.1

By Loopback 9 min read

Flat monochrome illustration: a localhost terminal showing 127.0.0.1 and ::1 with a returning path inside a laptop.

Loopback means sending something back to its starting point. In computer networking, a loopback connection lets a program communicate with the same system through its network stack. The familiar IPv4 address is 127.0.0.1, the IPv6 equivalent is ::1, and localhost is the special hostname used for local connections.

Open http://127.0.0.1:8000 in a browser and you are asking for a service on port 8000 of the system running that browser. You are not asking your router to find a website on the internet. If nothing is listening there, the connection fails even when your internet connection works perfectly.

Loopback connections stay inside the system

An operating system provides a software loopback interface so network applications can exchange traffic locally. A browser connects to a listening server through familiar protocols such as TCP and HTTP. The operating system delivers the traffic internally instead of transmitting it through an Ethernet or Wi-Fi adapter.

The FreeBSD lo(4) manual describes this software mechanism. FreeBSD calls its usual loopback interface lo0. Linux normally calls it lo. Both names identify software interfaces.

Local communication can work without an internet connection. A development web server, local database or application health check can use loopback without a connected network cable. The application may still have outside dependencies. A locally served page might still request fonts, APIs or authentication from an outside service.

Loopback, localhost and the common addresses

These terms describe related parts of a connection:

Term Meaning Common use
Loopback A mechanism for communicating back to the same system Local networking and testing
localhost A special hostname that resolves to loopback A readable name in a URL or configuration
127.0.0.1 The usual IPv4 loopback address An explicit IPv4 connection
::1 The IPv6 loopback address An explicit IPv6 connection
lo or lo0 A software interface name Inspecting addresses and local traffic
0.0.0.0 The IPv4 wildcard when binding a listening socket Accepting connections on local IPv4 addresses

RFC 1122 reserves the IPv4 127.0.0.0/8 block for internal host loopback. The /8 identifies the first eight bits. The reservation covers addresses beginning with 127, including 127.0.0.1. These addresses must not appear outside the host. Using another address in that range still requires understanding how the operating system and application handle it.

IPv6 uses the single address ::1, written in full as 0:0:0:0:0:0:0:1. RFC 4291 specifies that packets destined for it stay within one node and routers must not forward them. It is different from ::, the unspecified address.

How the localhost name resolves

RFC 6761 gives localhost special treatment. Name-resolution software should recognize it and return loopback addresses without sending the lookup to an ordinary upstream DNS server. Local configuration and application behavior can affect which address a client tries first.

A server listening only on 127.0.0.1 is not necessarily listening on ::1. When diagnosing a localhost problem, test the explicit address that matches the listener. The port matters too. A server on port 8000 will not answer a connection to port 3000 just because both URLs contain localhost.

The history of loopback and localhost

The current behavior developed through successive internet specifications. Early IPv4 used address classes, with a Class A network identified by its first octet. That is the historical setting for reserving the whole network numbered 127.

Date Documented milestone
September 1981 Jon Postel's RFC 790 lists network 127 as reserved. It does not label that entry as loopback.
November 1986 Joyce Reynolds and Jon Postel's RFC 990 explicitly assigns network 127 the loopback function, with traffic returning inside the host.
October 1989 RFC 1122 includes internal host loopback in the requirements for internet hosts and says those addresses must not appear outside a host.
December 1995 The early IPv6 addressing specification, RFC 1884, defines the single loopback address now written as ::1.
June 1999 RFC 2606 reserves .localhost, recording that existing implementations already associated the name with the loopback address.
February 2013 RFC 6761 specifies how applications, resolvers and DNS servers should handle localhost names.

The distinction between reservation and explicit documentation matters. RFC 6890 records September 1981 as the allocation date for 127.0.0.0/8. The 1986 document supplies an explicit description of its loopback purpose. Neither date, by itself, establishes when someone first implemented local packet delivery.

Why the number 127? The early records document its reservation and assigned use. They leave the reason for choosing 127 and the identity of an original inventor unresolved. The useful historical result is that applications gained a well-known local destination independent of a machine's changing network address.

Binding to loopback versus all interfaces

A server's bind address determines which local address it listens on. Binding an IPv4 service to 127.0.0.1 restricts that listener to loopback. Binding to 0.0.0.0 requests the IPv4 wildcard, covering local IPv4 addresses. The Linux ip(7) manual documents this socket behavior.

The wildcard expands the addresses on which the service accepts connections. Access through a LAN or public interface still depends on routing and firewall policy. Check the actual listener instead of relying on an application's description of its default settings.

For IPv6, a wildcard listener is commonly shown as [::]:8000. Whether it also accepts IPv4 connections depends on the operating system and socket settings, including IPV6_V6ONLY. The Linux IPv6 manual explains that distinction. Avoid assuming an IPv6 wildcard means IPv6-only access.

Use 127.0.0.1 or ::1 as a local destination. Treat wildcard addresses in listener output as configuration information, not as interchangeable spellings of localhost.

Try a local loopback web server

This example needs a Unix-style shell, Python 3 and curl. It uses an unprivileged port and a new temporary directory. The HTTP and Linux inspection commands were tested on CachyOS with Linux 7.2.2 and Python 3.14.7. The FreeBSD commands below were checked against the FreeBSD 15.1 manuals, not executed on that release.

In the first terminal, create one test file and start a server:

Unix shell · start a loopback-only test server
loopback_demo_dir=$(mktemp -d)
printf 'Loopback test\n' > "$loopback_demo_dir/index.html"
python3 -m http.server 8000 --bind 127.0.0.1 --directory "$loopback_demo_dir"

Python's HTTP server documentation describes the bind and directory options. Keeping the file in a dedicated directory avoids serving an existing project or home directory. This server is for the demonstration, not production hosting. If port 8000 is already occupied, choose an unused unprivileged port and change it in every command.

In a second terminal on the same system, request the page:

Second terminal · request the test page
curl --noproxy '*' --fail http://127.0.0.1:8000/

The response should be Loopback test. The --noproxy '*' option prevents curl from sending this request through a configured proxy. A successful response verifies the local HTTP path and the running application. The router, external DNS and internet connection are outside this test.

Stop the server with Ctrl+C in the first terminal. Then remove the test file and its temporary directory from that same shell:

First terminal · clean up after stopping the server
rm -- "$loopback_demo_dir/index.html"
rmdir -- "$loopback_demo_dir"

Inspect the interface and listening port

On Linux, inspect the loopback interface and the demonstration's TCP listener:

Linux shell · inspect loopback and port 8000
ip address show dev lo
ss -ltn 'sport = :8000'

The ip-address manual documents interface address inspection. A typical configured host shows 127.0.0.1/8 and ::1/128. In ss output, look for 127.0.0.1:8000 under the local address column. After stopping the server, that listener should disappear.

On FreeBSD, the corresponding read-only checks are:

FreeBSD shell · documentation-reviewed inspection
ifconfig lo0
sockstat -l -P tcp -p 8000

FreeBSD sockstat(1) can filter listening sockets by protocol and port. Read the local address column, since a wildcard in a foreign-address column has a different meaning. Our FreeBSD and Linux comparison explains why administration tools differ between these systems.

A separate Linux test checks ICMP echo replies:

Linux shell · check IPv4 and IPv6 loopback
ping -c 3 127.0.0.1
ping -6 -c 3 ::1

A reply demonstrates a working local ICMP path. HTTP availability and the physical network adapter need separate tests. An HTTP failure after a successful ping is a reason to inspect the application and its listening port.

Flat monochrome illustration: docker whale above separate containers, each with its own 127.0.0.1 loopback path.
Containers with separate network namespaces each have their own loopback.

Why localhost changes inside containers

Loopback belongs to a networking environment. Linux uses network namespaces to isolate interfaces, protocol stacks, routing tables and sockets. A container with its own network namespace has its own loopback.

If a program inside such a container connects to 127.0.0.1, it reaches that container's networking environment. It does not automatically reach a database on the Docker host or a second container. Sharing the host network or another container's network namespace changes this arrangement, so check the selected network mode.

Docker's networking documentation describes these modes and how containers connect. For applications on a user-defined network, a service name can identify another container. Replacing every host setting with localhost can make otherwise correct configurations fail.

Published ports introduce another address choice: the host address receiving traffic. Docker's port-publishing documentation explains that omitting the host address publishes to all host addresses by default. Specifying a loopback address on the host limits that exposure under the documented configuration. Review the installed Docker version and network mode, since the documentation also records older-release exceptions.

What loopback does and does not protect

A loopback-only listener reduces direct network exposure, but it does not authenticate clients. Other permitted processes in the same network namespace can attempt to connect. A reverse proxy, tunnel or application that forwards requests can also provide a path to an otherwise local service.

Keep authentication enabled on administrative services that support it, and review how proxies connect to their backends. Check the address, port and network namespace together. A label such as “local API” is not enough to establish who can reach it. Assess each service using its actual socket configuration and access controls.

Router loopback interfaces have another role

Network equipment also uses logical loopback interfaces for stable management or routing addresses. Juniper's interface documentation explains their use in identifying a device independently of an individual physical interface.

An administrator can assign a routable address to such an interface and advertise a route to it. That address can be reachable from elsewhere in the network. This is different from trying to route the reserved host addresses 127.0.0.1 or ::1. The interface's name alone does not tell you whether its configured address is externally reachable.

Loopback.zip is this publication's domain name. It has no special localhost behavior. Opening the site makes a normal website request. The name refers to the networking concept, while the .zip domain has its own ordinary DNS and browser behavior.

Sources