What is the 127.0.0.1 IP address and how do you use it?

0
TAW4/Shutterstock.com

127.0.0.1 is a pretty famous IP address – you may have even seen it on a t-shirt. But what exactly is it, and why is it so famous? Learn more about 127.0.0.1 here.

Addresses reserved on the Internet

The internet is made up of billions of devices. They identify and communicate with each other using IP addresses, which are conceptually similar to telephone numbers. Internet Protocol version 4 (IPv4), which has been in use for decades, allows nearly 4.3 billion such addresses. IPv4’s successor, IPv6, has over 10^38 addresses available – enough for every grain of sand on Earth, every star in the observable universe, and every atom in every person’s body to each have a unique IP address, with lots left over.

Despite the large number of IP addresses now available, it is convenient to reserve certain addresses, or even ranges (usually called blocks) of addresses, for specific purposes to avoid scheduling conflicts. Reserving addresses for specific purposes makes it easier to establish general rules and behaviors for different IP addresses. Reserved IP addresses, like most Internet standards, are established through documents called Requests for Comments or RFCs.

It turns out that it is often useful for a computer to talk to itself rather than to another computer. For this you need a special reserved IP address with unique properties – 127.0.0.1.

RELATED: The Foundation of the Internet: TCP/IP Turns 40

What is 127.0.0.1

127.0.0.1 is a host loopback address. Host loopback refers to the fact that no data packet addressed to 127.0.0.1 should ever leave the computer (host), sending it – instead of being sent to the local network or the Internet, it simply “loops” back to itself, and the computer sending the packet becomes the recipient.

RFC 1122 explicitly states that “the loopback address of the internal host. Addresses in this form MUST NOT appear outside a host.” Therefore, routers that pick up traffic directed to 127.0. packets immediately.This ensures that no traffic exclusively intended to be on the host computer ever makes it to the Internet.

Although the most common and famous, 127.0.0.1 is just one address on a large block, 127.0.0.0 – 127.255.255.255, which is reserved for loopback purposes in RFC 6890.

IPv6 also has a loopback address. Fully written, it is 0000:0000:0000:0000:0000:0000:0000:0001, although it is usually truncated to ::1 for convenience.

How to use 127.0.0.1

So why would you want the packets to loop back to the same computer? There are a few common use cases.

The first is for testing purposes – if you have a server or website that you intend to host on a local network or the Internet, you can run the server and client on the same computer to make sure that all the fundamentals are working properly first. For example, if you host a dedicated Minecraft server on your local computer, you would connect to it by entering 127.0.0.1 as the IP address. The same would apply to almost any locally hosted server. Removing networking complications, such as port configuration and latency issues, for example, can make the troubleshooting process more efficient.

It’s also possible that you just want to run a service that is only accessible to you, on your local device. This is relatively common in the self-hosting community – it doesn’t make sense to unnecessarily expose a service to external devices and threats.

The hosts file can be used to specify which IP address corresponds to a given domain name. Functionally, this allows you to use 127.0.0.1 in your hosts file to block web traffic. For example, if you were to tell your computer to search for facebook.com at 127.0.0.1, it would fail to connect, effectively blocking it unless you remembered the actual facebook.com IP address.

What is localhost

In most cases, localhost is just a shortcut that refers to 127.0.0.1 by default. It can be changed though – if you edit your hosts file you can make localhost refer to one of the 127.XXX reserved addresses. You can also create other local hosts, like localhost2, which can refer to 127.0.0.2, for example.

As IPv6 is adopted more rapidly, it is likely that more and more devices will use ::1 as the default loopback address. However, 127.0.0.1 has been in use for decades and will remain so for the foreseeable future.

Share.

Comments are closed.