Skip to content

What Is the Localhost IP Address (127.0.0.1) and How to Find Your Local IP

3 min read

Applies to: Linux, Windows and macOS; Linux commands tested on Ubuntu 26.04.1 (iproute2, iputils-ping), macOS commands run on macOS 27, Windows commands from Microsoft documentation

The localhost IP address is 127.0.0.1 for IPv4 and ::1 for IPv6. Both always point to the computer you are on, and traffic to them never leaves that computer. It is the same on every Linux server, Windows PC and Mac, so you don’t need to look it up: what people usually want to find is their local network IP, which is explained further down.

Why 127.0.0.1?

The whole block 127.0.0.0/8 (127.0.0.0 to 127.255.255.255) is reserved for loopback in the IANA special-purpose address registry, and RFC 6761 says that address lookups for the name localhost should always return the loopback address. On Linux any address in that block answers, not just 127.0.0.1:

$ ping -c1 127.45.6.7
64 bytes from 127.45.6.7: icmp_seq=1 ttl=64 time=0.005 ms

Check what localhost resolves to

On Linux, the name comes from /etc/hosts, which is read before DNS (hosts: files dns in /etc/nsswitch.conf):

$ getent hosts localhost
::1             localhost ip6-localhost ip6-loopback
$ ping -c1 localhost
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.009 ms

Note that localhost answered on the IPv6 address ::1 first in our test. That matters when a program listens only on 127.0.0.1: connect to 127.0.0.1 directly if “localhost” does not work.

The loopback interface itself is called lo on Linux and lo0 on macOS:

$ ip addr show lo
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host proto kernel_lo

$ ifconfig lo0        # macOS
	inet 127.0.0.1 netmask 0xff000000
	inet6 ::1 prefixlen 128

Find your local (network) IP address

This is the address your computer or server has on its network card. It is different on every machine.

Linux:

hostname -I              # all addresses except loopback
ip -br addr              # one line per interface
ip route get 1.1.1.1     # the address used for outgoing traffic ("src")

Sample output from our test container:

$ ip route get 1.1.1.1
1.1.1.1 via 172.17.0.1 dev eth0 src 172.17.0.2 uid 0

Windows: open Command Prompt and run ipconfig. According to Microsoft, without parameters it shows the IPv4 and IPv6 addresses, subnet mask and default gateway of every adapter; look for “IPv4 Address” under your active adapter. In PowerShell: Get-NetIPAddress -AddressFamily IPv4.

macOS: ipconfig getifaddr en0 prints the IPv4 address of the interface en0. To see which interface your Mac actually uses, run route -n get default and read the interface: line.

Local IP, private IP and public IP

Addresses in 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 are private-use ranges (RFC 1918): they work inside your home or office network but can’t be reached from the internet. At home, the router usually shares one public IP between all your devices. To find the public address of a server, see 4 ways to find a server’s public IP address, or find your server IP address and location for a Ucartz service.

Why localhost matters on a server

  • Services that listen on 127.0.0.1 can only be reached from the server itself. In sudo ss -ltn, a local address of 127.0.0.1:3306 means local only, while 0.0.0.0:22 means every IPv4 address of the server. Keep databases and application back ends on 127.0.0.1 and put a web server in front.
  • MySQL and MariaDB treat “localhost” specially. According to the MySQL manual, on Linux a client connecting to localhost uses the Unix socket file, not TCP; use 127.0.0.1 or --protocol=TCP to force TCP. In our test, MySQL 8.4 with networking switched off still accepted connections to localhost for that reason. For database settings in hosting accounts, see localhost or remote MySQL host.
  • Testing a site before DNS points to it is done with the hosts file, and building one on your own computer uses localhost: see how to host a website on localhost.

Official documentation: IANA IPv4 special-purpose address registry and RFC 6761.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Linux server management

hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.

Was this answer helpful?

Still stuck? Open a ticket