What Is Localhost and How Is It Different from 127.0.0.1?

What Is Localhost and How Is It Different from 127.0.0.1? Featured Image

Even when every network device is disconnected, your computer can still communicate over a kind of network. Known as a “loopback,” a Unix machine can send and receive network communications from itself and to itself over a virtual network device. Your computer can send messages from itself to itself, permitting network-style communications without the need for a functioning network.

What is 127.0.0.1?

127.0.0.1 is the most commonly-used loopback IP address. It’s part of the reserved block of more than sixteen million IP addresses that are used specifically for loopback functionality. A loopback allows your computer to communicate with itself while using networking connection protocols.

difference-localhost-127-0-0-1-ipconfig-lo

In broad abstraction, a loopback is a virtual networking device that creates a network connection with only one endpoint, meaning that it begins and ends at the same device: your computer. In fact, the loopback device even shows up in ipconfig with the name lo, as seen above. The loopback addresses are primarily used for troubleshooting (it’s similar to looking in a mirror) or to access local resources over a network interface.

Also read: How to Use Nginx as a Reverse Proxy

What is localhost?

difference-localhost-127-0-0-1-networking

“localhost” describes a communication port that connects to the originating server. It allows a network connection to “loop back” on itself, permitting you to emulate network connections when no such network is present or available. In practice, localhost is treated as synonymous with 127.0.0.1 for usage and discussion. However, it’s important to remember that they are not strictly identical.

Before making a DNS request to translate the text string typed by the user into a navigable IP address, the operating system checks the HOSTS file for any aliases or redirect rules. On a system configured to standard defaults, “localhost” in a URI will resolve to 127.0.0.1 under IPv4 or ::1 for IPv6. There are far more loopback addresses than just those two, however. The block of IP addresses reserved for loopback addresses stretches from 127.0.0.0 to 127.255.255.255.

In most all cases localhost will resolve to 127.0.0.1, thanks to a redirect rule in the HOSTS file, as mentioned above. But in some cases, localhost may be mapped to a different IP address. So, localhost could be pointed to any IP address in that block, and it would function identically.

Conclusion: What’s the Difference Between localhost and 127.0.0.1?

On most machines localhost and 127.0.0.1 are functionally identical. But localhost is a label for the IP address and not the address itself. Localhost could be pointed at different IP addresses. In fact, it could be pointed at any IP address, even one outside the reserved address block. The HOSTS file doesn’t care and won’t stop you. However, it will break significant functionality on your system and crash any app that relies on a localhost connection.

The 127 block of addresses was chosen for the loopback address block because it was the last block of Class A addresses, which run from the binary address value 00000001 to 01111111. In IPv6, the loopback address is the first address, 0:0:0:0:0:0:0:1, most frequently expressed in its truncated form as ::1.

If you’re coming from Windows to a Unix system, you might have noticed that loopback is practically synonymous with localhost. You can use your HOSTS file to make “loopback” redirect to 127.0.0.1, but that’s more of a text replacement than anything else.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Alexander Fox Avatar

Read next

Suzanne Simard sealed paper birch and Douglas fir seedlings inside plastic bags, fed them carbon-14 and carbon-13 dioxide, and nine days later found carbon had crossed between species through fungal threads in the British Columbia soil beneath her boots
A species of jellyfish called Turritopsis dohrnii can revert its adult cells back to a juvenile polyp stage when injured or starving, effectively restarting its life cycle, and biologists have so far failed to identify any natural limit to how many times it can do this.
A Japanese man named Jiroemon Kimura, who lived to 116, was born in 1897 when Queen Victoria still ruled and died in 2013, meaning a single human life personally overlapped with the invention of the airplane, the atomic bomb, the internet, and Instagram
The Hollywood sign originally read HOLLYWOODLAND when it was built in 1923 as a real estate advertisement for a housing development, and it was only meant to stand for 18 months, but nobody ever got around to taking it down and the city eventually adopted it as a landmark
Almost all of the world’s internet traffic does not travel by satellite but through fibre-optic cables lying on the ocean floor, a hidden web of wires crossing the deepest parts of the sea to connect the continents.
People who flip their phone face down on every table aren’t being secretive. They figured out that staying interruptible meant handing their time to whoever rang first
Twitch vs. Facebook Gaming vs. YouTube Gaming: What’s the Best Live Game Streaming Platform?
Chrome Extensions Ownership Transfer is a Direct Threat to You: How to Stay Safe