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.
Reserved addresses on the Internet
The Internet is made up of billions of devices. They identify and communicate with each other through 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. The successor of IPv4, 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 have a unique IP address, and there are plenty of those left. finished.
Despite the vast number of IP addresses available today, it is a good idea to reserve some addresses, or even ranges (often called blocks) of addresses, for specific purposes to avoid scheduling conflicts. Reserving addresses for specific purposes makes it easy to set 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’s often useful for a computer to talk to itself rather than to another computer. For that, you need a special reserved IP address with some unique properties: 127.0.0.1.
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 leave the computer (host), sending it; instead of being sent over the local network or the Internet, it simply “forwards” itself, and the sending computer becomes the recipient.
RFC1122 explicitly says that “Internal host loopback address. Addresses in this form MUST NOT appear outside of a host.” As a result, routers that pick up traffic addressed to 127.0.0.1 are supposed to drop the packets immediately. This ensures that no traffic intended solely to be on the host computer reaches the Internet.
Although it is the most common and famous, 127.0.0.1 is just one big block address, 127.0.0.0 – 127.255.255.255, which is reserved for loopback in RFC 6890 .
IPv6 also has a loopback address. Fully typed 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 go back to the same computer? There are some common use cases.
The first is for testing purposes: if you have a server or a website that you ultimately want to host on a LAN or the Internet, you can run the server and client on the same computer to make sure all the basics work properly first. For example, if you were hosting a dedicated minecraft server on your local machine, you would connect by entering 127.0.0.1 as the IP address. The same would apply to almost any locally hosted server. Eliminating network-related complications like 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 only can be accessed by you, on your local device. This is relatively common in the self-hosting community: there is no point in unnecessarily exposing 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 on your hosts file to block web traffic . For example, if you told your computer to look for facebook.com at 127.0.0.1, it wouldn’t connect, effectively blocking you unless it had memorized the real IP of facebook.com.
What is localhost?
In most cases, localhost is just a shorthand that refers to 127.0.0.1 by default. However, it can be changed: if you edit your hosts file, you can make localhost refer to any of the reserved 127.XXX addresses. You can also create other local hosts, such as localhost2, which might refer to 127.0.0.2, for example.
As IPv6 is more rapidly adopted, 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 continue to be in use for the foreseeable future.