Localhost (127.0.0.1) (2024)

When you (or your computer) call an IP address, you are usually trying to contact another computer on the internet. However, if you call the IP address 127.0.0.1 then you are communicating with the localhost – in principle, with your own computer. But what is the point of starting a virtual conversation with yourself? What do you need the localhost for and how does it work?

Contents

  1. What is localhost?
  2. 127.0.0.1 – how does loopback work?
  3. What is localhost used for?
    1. For Testing Purposes
    2. To block websites

Cheap domain names

Domains as original as your ideas. What are you waiting for?

Make your project a success with the perfect domain extension!

Email account

Wildcard SSL

24/7 support

What is localhost?

The first point to make when explaining what a localhost is, is that it is always your own computer: when you call the localhost, your computer is talking to itself. However, this is a condensed approach. The localhost is not always directly identified with your computer. In most cases, it has a separate IP address like 192.168.0.1. within your personal network, which is different to the one you use on the internet, and is usually dynamically assigned by the internet service provider. When you are talking about a localhost, you are referring to when a server is used on your own computer.

Conversely, this means that the term is only used in the context of networks. “Localhost” is not just the name for the virtual server, but also its domain name. Just like .test, .example or .invalid,., .localhost is a top-level domain reserved for documentation and testing purposes. When you try to access the domain, a loopback is triggered. If you access "http://localhost" in the browser, the request will not be forwarded to the internet through the router, but will instead remain in your own system. Localhost has the IP address 127.0.0.1, which refers back to your own server.

127.0.0.1 – how does loopback work?

IP addresses are used within a network to communicate with each other. Each participant in the network has their own address. Data packets sent via TCP/IP are able to reach the correct destination when this system is used. The protocol pair Transmission Control Protocol (TCP) and Internet Protocol (IP) are some of the cornerstones of the internet. However, TCP/IP is also used outside the internet, in local networks. During transmission, the Internet Protocol is responsible for allowing the IP address and subnet mask to address subscribers in a network.

The allocation of public IP addresses (those that can be reached through the internet) is regulated by an international organisation: the Internet Corporation for Assigned Names and Numbers (ICANN). ICANN is also responsible for the allocation of domain names, or the Domain Name System (DNS). However, certain address ranges are reserved for special purposes, like the range from 127.0.0.0 to 127.255.255.255. There is no reliable information on why that range was chosen, but you are free to speculate.

Until the 1990’s, IP addresses on the internet were divided into different classes. The first class (Class A) started with 0.0.0.0 (this address is also reserved) and ended with 127.255.255.255. 127 is the last block within the Class A network. This important position could have been the reason why it was chosen.

A Localnet can be set up within this address range. The special thing about this range is not only that it was reserved by ICANN, but is also that IP addresses are not uniquely assigned in it, as is usually the case. But how does it work?

Fact

With IPv6, the address ::1 is reserved for loopbacks.

For example, if you enter an IP address (or corresponding domain name) in your browser, the router will forward your request to the internet and to the correct server. This means that if you enter 172.217.0.0, you will reach the Google homepage. However, the situation is different with 127.0.0.1 because requests to this address will not be forwarded to the internet. TCP/IP recognises from the first block (127) that you don’t want to access the internet, you are calling yourself instead. This then triggers the loopback.

Fact

Conversely, the protocol does not accept external requests addressed to 127.0.0.1, as it would mean that attackers could try to sneak into their system. Packets reportedly appearing on the internet from reserved IP addresses like 127.0.0.1 are known as Martian Packets.

A loopback device is created so that the back link to your own computer works. This is a virtual interface that is created through the operating system. With Unix systems, the interface is called lo or lo0 and can also be displayed using the ifconfig command. A similar command for Windows is ipconfig.

Fact

If you consider the technology independently of the local host, a loopback can be created in an analogue way: circuits in communication technology can then be used to determine whether the paths taken by the signal and the reception are correct.

What is localhost used for?

Developers use the local host to test programs and web applications. Network administrators can also use the loopback to test network connections. Another practical use for the localhost is the hosts file, where you can use the loopback to block malicious websites.

For Testing Purposes

Localhost’s main use in web servers is for programming applications that need to communicate over the internet. During development, it is important to find out whether the application actually works as hoped once it has internet access. Localhosts’ other functions are only possible if the required files can be found on the internet - for example, there is a difference between opening a HTML document on your PC or loading it onto a server and accessing it. Releasing an unfinished product without testing it doesn’t make sense, so developers use a loopback to test them. They can stimulate a connection while also avoiding the network detour: the connection instead just stays completely inside their own system.

Another advantage of using localhost for testing purposes is its speed. When you send a request over the internet, it takes more than 100 milliseconds. If you send a ping to localhost, the maximum transmission time is just one millisecond. With this technology, you can also find out whether or not the Internet Protocol is correctly implemented. To test this yourself, just open the command prompt (Windows) or terminal (Unix/Mac) and use the ping command. You can either send it to the domain localhost or directly to the IP address.

ping localhost

ping 127.0.0.1

If you want to set up your own test server on your PC to address it through the localhost, you first need to install the right software. It is generally possible to run any standard web server on your own computer, but there is also special software specifically designed for use as a localhost – XAMPP for example. We provide a step by step guide for how to install and configure the test system in our Digital Guide.

SSL certificates from IONOS

Protect your domain and gain visitors' trust with an SSL-encrypted website!

Easy activation

Proven safety

24/7 assistance

To block websites

Localhost also plays a role in the hosts file. In principle, this file is a predecessor of the Domain Name System (DNS): in it IP addresses can be assigned to the corresponding domains. If you enter a website address in the browser, the domain name needs to be translated into an IP address. It used to be the host file, but today you would usually use the global DNS. However, the host file is still present in most operating systems. With Windows, you can find the file under \system32\drivers\etc\hosts; with macOS and other Unix systems, it is found under /etc/hosts.

If you yourself have not made any file changes, there are probably these two entries left:

127.0.0.1 localhost

::1 localhost

This ensures that name resolution for the localhost does not have to be done over the internet. You can also use the file to block certain websites. To do this, enter the website to be blocked into the list and assign the domain the IP address 127.0.0.1. If you – or perhaps a malicious script – try to call up the locked domain, the browser will check the hosts file first, and find your entry there. Another option is to use the domain name 0.0.0.0.

The browser will then try to access the corresponding website on the server with 127.0.0.1. However, it is unlikely that the browser will be able to locate it, because the requested file will not be there. However, if you have set up your own test server, then the browser may find home.html, but this is just your own file. If you have not set up your own test server, an error message will appear instead of the requested website. This technology can also be used to switch off ad inserts throughout the system. To not have to make every entry manually, you can find finished and regularly extended host files on the Internet.

Note

The hosts file could have a major impact on your security when browsing the internet. Although the file is suitable for blocking malicious websites, criminals can still manipulate it too. You therefore need to make sure that you do not copy entries from other websites without checking them first, and also make sure that malware does not try to make entries without you realising either.

  • Know-how
  • Network

Related articles

Localhost (127.0.0.1) (3)

Use subnetting to get the most out of your network

Dividing a corporate network into smaller subnets has some advantages in terms of speed, security, and logical organisation. However, many people find it difficult to set up. Binary computational operations and long series of numbers are frightening, but the principle itself is not so complicated. We explain what subnetting is, how to calculate a subnetmask, and what you need subnets for, so that…

Use subnetting to get the most out of your network

Localhost (127.0.0.1) (4)Maksim KabakouShutterstock

XAMPP tutorial: installation and first steps

The software packet XAMPP is a collection of popular applications like the web server Apache, a leading database management system (either MySQL or MariaDB), the scripting languages PHP and Perl, and more – all together in a compact test server. Our XAMPP tutorial will take you through the installation and configuration process, with the aid of clear instructions and screenshots, to help you set…

XAMPP tutorial: installation and first steps

Localhost (127.0.0.1) (5)

What is the Server Name Indication (SNI)?

What is server name identification, really? Encryption technologies play a big role when it comes to surfing on the net. Credit card data and other personal information must not fall into the hands of criminals. For now, TLS is one of the protocols used for this purpose. But it has a disadvantage: it only functions when each IP address only hosts one domain. If multiple virtual services are…

What is the Server Name Indication (SNI)?

Localhost (127.0.0.1) (6)

How to use SSH tunnels and SSH port forwarding

SSH tunnels are used for secure data transfers and for accessing websites that you otherwise wouldn’t have access to via your network. Reverse SSH tunnels make port forwarding possible with private IP addresses. Keep reading our dedicated article to find out what SSH tunnels are, what they’re used for and how to set one up.

How to use SSH tunnels and SSH port forwarding
Localhost (127.0.0.1) (2024)

FAQs

Can I use 127.0 0.1 instead of localhost? ›

More often than not, localhost and 127.0. 0.1 are used interchangeably. The two are considered the same thing.

How is 127.0 0.1 different with localhost? ›

localhost is a hostname that can be customized to resolve to a different IP address, while 127.0. 0.1 is a numeric IP address that is hard-coded into the network stack of the operating system.

Is 127.0. 0.1 safe? ›

If someone already has access to your network, they can exploit 127.0. 0.1 in more targeted ways: Misconfigured Services: Weaknesses in configuration or access controls of localhost services become easy targets for insiders, granting them access to sensitive data or functionalities.

What is IP 127.0. 0.1 used for? ›

It is also known as localhost. When a server is running on your local PC, it will be accessible at 127.0. 0.1. This IP address is reserved for loopback purposes and is not used to communicate with other devices like a real IP address.

Is 127.0 0.1 a valid IP address for a host? ›

The address 127.0.0.1 is the standard address for IPv4 loopback traffic; the rest are not supported by all operating systems. However, they can be used to set up multiple server applications on the host, all listening on the same port number.

What is the difference between 127.0 0.1 0.0 0.0 and localhost? ›

Localhost is an alias used to refer to IP addresses reserved for loopback. While IPv4 uses the last block of class A addresses (from 127.0. 0.1 to 127.255. 255), IPv6 reserves the first (0:0:0:0:0:0:0:1 - or : :1, in short) as its loopback address.

Does localhost work without internet? ›

IT staff and system admins can also use localhost to test the the local network without requiring an internet connection — they just need to send a request to localhost and monitor this request to ensure that the system's software and hardware are working.

Why is 127.0. 0.1 not working? ›

The default port number for the web server is 80. If you're trying to access it by typing localhost in your browser – which will direct to localhost:80 – but it turns out your web server is not configured to use the default port, you'll get the localhost error or 127.0 0.1 refused to connect message.

Can I change my localhost IP address from 127.0 0.1 to something else? ›

Yes, you can, but I cannot imagine any reason why you would need to. Every program and service which uses networking depends on localhost, and it is defined by standard to have the IP 127.0. 0.1. Changing the localhost IP address will break a lot of things.

Can 127.0 0.1 be spoofed? ›

It is possible to send data as fake 127.0. 0.1, but the reply will go "out" (stay inside actually) the loopback interface, and be 'lost'. If there is a router on the way, it will send the packet through it's own loopback interface, and it will be lost there.

Why is 127.0 0.0 not used? ›

All the addresses starting with 127 are dedicated to testing the connectivity but all zeros(127.0. 0.0) and all ones(127.255. 255.255) in address 127 is not allowed. All zeros represent the subnet id and all ones are generally used for BroadCasting.

What is the loophole address of IPv6? ›

It is an internal address that routes back to the local system. The loopback address in IPv4 is 127.0. 01. In IPv6, the loopback address is 0:0:0:0:0:0:0:1 or ::1.

What does ping 127.0 0.1 verify? ›

Type Ping 127.0.

0.1 is your local host address, and pinging it verifies whether the TCP/IP protocol is installed and functioning properly. If you cannot complete this ping, you can reconfigure your TCP/IP protocol or refer to your operating system documentation for more information.

What does 127.0 0.0 tell you explain its importance? ›

This is defined as “local host", usually its purpose is as a “loopback" to test that the internet protocol stack is working in a device — e.g. if a Ping to 127.0. 0.1 fails the problem is in the device, not the network it's connected to.

What does localhost mean? ›

Localhost is the hostname or the computer that is currently in use to run a program, in which the computer has the role as a virtual server. In web development, you can develop a server by editing the code in the localhost and exporting your data to the server.

Can I replace localhost with IP address? ›

You can't change the IP address for "localhost", it's by definition 127.0. 0.1 (for IPv4, IPv6 is not as simple).

Can I change my localhost IP address from 127.0. 0.1 to something else? ›

Yes, you can, but I cannot imagine any reason why you would need to. Every program and service which uses networking depends on localhost, and it is defined by standard to have the IP 127.0. 0.1. Changing the localhost IP address will break a lot of things.

What is the IP alternative for localhost? ›

So, if you type localhost to your browser's address bar, it transforms to the IP address 127.0. 0.1 . This 127.0. 0.1 IP address is reserved for local servers on computers, so you will never find another IP address that starts with 127.

How do I connect to 127.0 0.1 localhost? ›

How do I access localhost? You simply type 127.0. 0.1 into a web browser on your computer to access localhost. You have to set up a test server on your computer first before you can access it, though.

References

Top Articles
Latest Posts
Article information

Author: Rob Wisoky

Last Updated:

Views: 5862

Rating: 4.8 / 5 (68 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rob Wisoky

Birthday: 1994-09-30

Address: 5789 Michel Vista, West Domenic, OR 80464-9452

Phone: +97313824072371

Job: Education Orchestrator

Hobby: Lockpicking, Crocheting, Baton twirling, Video gaming, Jogging, Whittling, Model building

Introduction: My name is Rob Wisoky, I am a smiling, helpful, encouraging, zealous, energetic, faithful, fantastic person who loves writing and wants to share my knowledge and understanding with you.