What 127.0.0.1 Is
127.0.0.1 is the IPv4 loopback address. Traffic sent to it is handed straight back to the same machine, so a program that connects to 127.0.0.1 talks to another program on the same computer or server. The name localhost points to it, and the IPv6 loopback address is ::1. The whole 127.0.0.0/8 block is reserved for loopback, so on Linux 127.0.0.2 or 127.0.1.1 stay on the machine too, but 127.0.0.1 is the one used almost everywhere.
The Loopback Interface
ip addr show loThe output lists inet 127.0.0.1/8 and inet6 ::1/128 on the interface lo. The kernel handles this traffic internally: no network card is involved, and nobody outside the machine can send packets to these addresses.
Where the Name Comes From
The name localhost is not looked up in public DNS. It is defined in /etc/hosts, which most systems read before DNS (the order is set in /etc/nsswitch.conf):
127.0.0.1 localhost
127.0.1.1 myserver
::1 localhost ip6-localhost ip6-loopbackThis is a typical Debian or Ubuntu file. The installer often maps the server's own host name to 127.0.1.1 when there is no fixed address; a server with a permanent IP can list that address instead. AlmaLinux and Rocky Linux use a similar file. Leave the localhost lines in place, since many programs expect them.
127.0.0.1 vs 0.0.0.0
A service listens on one or more addresses, and that choice decides who can reach it:
| Listens on | Reachable from |
|---|---|
127. | This machine, IPv4 |
::1 | This machine, IPv6 |
0. | Every IPv4 address |
[:: | Every IPv6 address |
* | Every address, IPv4 and IPv6 |
203. | That address only |
A database that listens on 127.0.0.1 serves the website on the same server and cannot be reached from the internet at all, whatever the firewall says. That is why it is the safe default: the MariaDB packages on Debian and Ubuntu and the MySQL package on Ubuntu set bind-address = 127.0.0.1, and PostgreSQL's listen_ defaults to localhost. MySQL's own built-in default is every interface, so check other packages with ss. Open a database to the network only when another server needs it, and then allow only that server's address in the firewall.
See What a Service Is Bound To
sudo ss -ltnp-l shows listening sockets, -t TCP only, -n numbers instead of names, and -p the process. In the Local Address column, 127.0.0.1:3306 means a database that only local programs can use, and 0.0.0.0:80 means a web server open on every IPv4 address.
Fixing "Localhost Refused to Connect"
"localhost refused to connect" or "127.0.0.1 refused to connect", with ERR_
- Wrong machine: localhost in your browser is your own computer, not the server. An application running on the server needs the server's address or a tunnel.
- The application is not running, or uses another port: check with
ss -ltnpand its service status. - IPv4 versus IPv6: localhost can resolve to ::1 while the application listens only on 127.0.0.1, or the other way round. Test both with
curl http://127.0.0.1:8080/andcurl 'http://[::1]:8080/'. - Containers: inside a Docker container, localhost is the container itself. Publish the port, for example
-p 127.0.0.1:8080:80, and connect from the host. See how to install Docker on Ubuntu.
The same error for a public site is covered in ERR_
Reach a Loopback-Only Service Through an SSH Tunnel
To use an admin page or a database that listens on 127.0.0.1 on the server, forward a port over SSH from your own computer:
ssh -L 8080:127.0.0.1:8080 user@your_server_ipWhile this session is open, http://localhost:8080 on your computer reaches port 8080 on the server's loopback address. Add -N to forward without opening a shell, and -p with the port number if SSH listens elsewhere, as in how to change the SSH port. For a database, forward to another local port, such as -L 3307:127.0.0.1:3306, and point your client at 127.0.0.1 port 3307. The service stays closed to the internet the whole time.
Updated:
Linux VPS with Full Root Access
MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.
More Guides
No Limits on Service or Support
You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

- 100% customer satisfaction goal
- Our own hardware
- 24/7 ticket and email support
- 4 countries with locations