When you explain what a localhost is, the first point to take into account is that it is always from your own computer: when you call localhost, your computer speaks to itself. However, this is a condensed approach. Localhost is not always identified directly with your computer. In most in some cases, it has a separate IP address such as 192.168.0.1 in your personal network, different from the one you use on the Internet, and which is usually assigned dynamically by the ISP. When you talk about a host local, you are referring to a server used on your own computer .
Conversely, this means that the term is used only in the context of networks. "Localhost n is not just the name of the virtual server, but also its domain name. Just like .test, .example or .invalid, .localhost is un top-level domain reserved for documentation and testing purposes . When you try to access the domain, a loopback (looping in French) is triggered. If you access "http: // localhost " in the browser, the request will not be transmitted to the Internet via the router, but will remain on your own system. Localhost has the IP address 127.0.0.1, whichrefers to your own server. Exemplary representation of the communication between a web browser and a web server on a local computer figcaption >
127.0.0.1: how does loopback work?
IP addresses are used in a networku to communicate with each other. Each participant in the network has their own address. Data packets sent via TCP / IP can reach the correct destination when this system is used. The pair of 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 authorizing the IP address and the subnet subnet mask to address subscribers on a network.
The allocation of public IP addresses (accessible via the Internet) is regulated by an international organization: Internet Corporation for Assigned Names and Numbers (ICANN, in French the Company for the allocation of domain names and numbers on the Internet). ICANN is also responsible for the allocation of domain names or the Domain Name System (DNS). However, someOur address ranges are reserved for specific purposes , such as the range 127.0.0.0 to 127.255.255.255. There is no reliable information on why this range was chosen, but you are free to speculate.
Until the 1990s, 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. The last block of the class A network is 127. This important position could have been the reason for which it was chosen.
A Localnet can be configured in this range 'addresses. The peculiarity of this range lies not only in the fact that it is reserved by ICANN, but also that the IP addresses are not assigned to it in a unique manner, as is generally the case. But how does it work?
With IPv6, the address :: 1 is reserved for loopbacks.
For example, if you enter an IP address (or a corresponding domain name) in your browser, the router will transmit your request to the Internet and to the appropriate server. This means that if you enter 220.127.116.11, you access the Google homepage. However, the situation is different with 127.0.0.1 since requests to this address will not be sent to the Internet. TCP / IP recognizes from the first block (127) that you do not want to access Internet. This triggers loopback.
Conversely, the protocol does not accept external requests addressed to 127.0.0.1, as this would mean that the attackers could try to infiltrate their system. Packets appearing on the Internet from reserved IP addresses such as 127.0.0.1 are called Martian packets.
A loopback device is created to make the back to your own computer work. It is a virtual interface created via 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.
If you consider the technology independently of the local host, a loopback can be created analogically: the circuits of the communication technology can then be used to determine if the paths taken by the signal and the reception are correct.
What is the use of localhost?
Developers use the local host to test web programs and applications. Network administrators can also use the loopback to test network connections Another useful use of localhost is the hosts file, where you can use loopback to block malicious websites.
The main use of localhost in Web servers is for programming applications that need to communicate on the Internet. During development, it is important to know if the application is actually working as expected once you have access to the Internet. Other functions of local hosts are only possible if the required files are available on the Internet. For example, there is a difference between opening an HTML document on your PC or uploading it to a server and accessing it. Releasing an unfinished product without testing it makes no sense, so developers use a loopback to test them. They can stimulate a connection while avoiding the detour of the network: instead, the connection remains completely in their own system.
Another advantage of using localhost in tests is its speed. When you send a request over the Internet, it takes more than100 milliseconds. If you ping the localhost, the maximum transmission time is only one millisecond. With this technology, you can also know if the Internet protocol is correctly implemented or not. To test this yourself, simply open the command prompt (Windows) or the terminal (Unix / Mac) and use the ping command . You can either send it to the localhost domain or directly to the IP address.
If you want to configure your own test server on your PC to address it via the local host, you must first install the correct software. It is usually possible to run any standard web server on your own computer, but there is also software specially designed to be used as localhost - XAMPP, for example. We provide a step-by-step guide on how to install and configure thetest system with XAMPP in our Digital Guide.
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): IP addresses can be assigned to the corresponding domains. If you enter a website address in the browser, the domain name must be translated to an IP address. Previously, it was the host file, but today you would generally use 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 under /etc/hosts.
If you did not change the file, there are probably two entries left:
:: 1 localhost
This ensures that name resolution for localhost does not have to be done on the Internet. You can also use the file to block certain websites . To do this, enter the website to be blocked from the list and assign the IP address 127.0.0.1 to the domain. If you, or a malicious , try to call the locked domain, the browser will first check the hosts file 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, as the requested file will not be there. However, if you have set up your own test server, the browser may find home.html, but it is only your own file. If Vou 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 disable ad inserts throughout the system. To avoid having to make each entry manually, you can find host files regularly extended on the Internet.
The hosts file can 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. So you should make sure that you do not copy entries from other websites without first checking them, and make sure that malware does not attempt to create entries withoutrealize it.