When you (or your computer) call up an IP address , in most cases you want to contact another computer on the Internet. However, if you dial the IP address 127.0.0.1 , you are communicating with the localhost - and thus in principle with your own computer. But why should you have virtual self-talk? What do you need the localhost for and how does the reference work?
What exactly is the localhost?
The first approach when explaining localhost is always that it is your own computer: when you call up localhost, your computer is speaking to itself. This is, however, a shortened view. The localhost is not directly about your own PC. In most cases this has an IP address such as 192.168.0.1 within the personal network. The address with which you are on the Internet is in turn different and is usually assigned by the Internet provider - usually dynamically. One speaks of a localhost when a server is used on one's own computer . Conversely, this means that the term is only used in the context of networks. "Localhost" is not only the name for the virtual server, but also its domain name. Just like .test, .example or .invalid, .localhost is a top-level domain that is reserved for documentation and testing purposes. When you try to access the domain, a loopback loop is triggered. If you call up "http: // localhost" in your browser, the request will not be forwarded to the Internet via the router, but will remain in your own system. Localhost has the IP address 127.0.0.1, which refers to the server on your own computer.
127.0.0.1 - How Does Loopback Work?
You use IP addresses within a network so that you can communicate with each other. Each participant in the network has its own address. Due to this system, data packets that are sent via TCP / IP reach the correct destination. The protocol pair Transmission Control Protocol (TCP) and Internet Protocol (IP) is one of the cornerstones of the Internet. Beyond the Internet, TCP / IP is also used in local networks. During transmission, the Internet Protocol is responsible for ensuring that participants in a network can be addressed using the IP address and subnet mask . The allocation of public IP addresses (i.e. those that can be reached via the Internet) is regulated by an international organization: the Internet Corporation for Assigned Names and Numbers (ICANN). ICANN also takes care of the Domain Name System (DNS), i.e. the assignment of domain names. However, certain address areas are reserved for special purposes , e.g. E.g. the range from 127.0.0.0 to 127.255.255.255. One may wonder why exactly this area was chosen. There is no reliable information, but an answer can at least be approached. Until the 1990s, IP addresses were divided into different classes within the Internet. The first class ( Class A ) began 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 prominent place could have been the reason for the choice.Under IPv6 the address :: 1 is reserved for loopback. A localnet can be set up within this address range . What is special about this address range is not only that it was reserved by ICANN, but also that the IP addresses in it are not assigned once, as is otherwise the case. How can this work? For example, as soon as you enter an IP address (or the corresponding domain name) in your browser, the router forwards your request to the Internet and to the correct server. Therefore, if you enter 220.127.116.11, you will reach the Google homepage. The case is different for 127.0.0.1, because requests to this address are not forwarded to the Internet. TCP / IP recognizes from the first block (127) that you do not want to send to the Internet, but refer to yourself. Therefore the loopback is triggered. Conversely, the protocol does not allow any external requests directed to 127.0.0.1. Attackers could try to sneak into your own system. Packets that supposedly appear on the public Internet from reserved IP addresses such as 127.0.0.1 are also called Martian Packets. A loopback device is created so that the reference back to your own computer works. This is a virtual interface . This is completely implemented via the operating system. On Unix systems, the interface is called lo or lo0 . These can also be displayed here using the ifconfig command . A comparable command on Windows is ipconfig . If the technology is viewed independently of the local host, a loopback can also be implemented in an analog manner: Circuits in communication technology can be used to determine whether both the path taken by the signal and the reception are correct.
What do you use localhost for?
Developers use localhost when testing programs and web applications. Network administrators can also use the loopback loop to test network connections. The localhost finds another practical use in the hosts file , where loopback can be used to block malicious websites.
For testing purposes
Localhost is mainly used in the field of web servers and when programming applications that have to communicate over the Internet. During development, it is important to find out whether the application works as it is designed to work when accessed over the Internet. Other functions can only be executed if the corresponding files can be found on the (pseudo) Internet. It makes z. For example, it makes a difference whether you simply open an HTML document on your PC or load it onto a server and access it in this way. But releasing an unfinished product doesn't make sense. Developers use loopback for this. Programmers can simulate a connection in this way, but bypass the detour via the network: the connection remains completely in its own system.
Another advantage of using localhost for test purposes: the speed. If you send a request over the Internet, it can take over 100 milliseconds. If you ping localhost , the transmission should take a millisecond or less. This technique can also be used to find out whether the Internet protocol is implemented correctly. To test this yourself, all you have to do is open the command prompt (Windows) or Terminal (Unix / Mac) and use the ping command . You can either send this to the localhost domain 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 in order to address it via localhost, you have to install the appropriate software. In general, it is possible to run any standard web server on your own computer. But there is also special software that is specially designed for use as a localhost.
To block websites
Localhost also plays a role in the hosts file . In principle, this file represents a predecessor of the Domain Name System (DNS): In it, IP addresses can be assigned to the corresponding domains. If you enter the address of a website in the browser, the domain must be translated into an IP address. In the past, the hosts file was used for this. Nowadays, however, the global DNS is usually used. The file is still present in most operating systems. Under Windows you will find this under \ system32 \ drivers \ etc \ hosts ; on macOS and other Unix systems under / etc / hosts . If you haven't made any changes to the file yourself, you will likely only find two entries there: 127.0.0.1 localhost :: 1 localhost This ensures that the name resolution for localhost does not have to run over the Internet. The file can also be used to block certain websites . To do this, enter the website to be blocked in the list and assign the domain the IP address 127.0.0.1. If you - or a malicious script, for example - should try to access the blocked domain, the browser will first look in the hosts file and find an entry there. Another possibility is to use the IP address 0.0.0.0.
The browser then tries to access the corresponding document (the website) on the server at 127.0.0.1. However, it will most likely not find it because the requested file is not there. However, if you have set up your own test server, it is possible that the browser will find a home.html , which is your own file. If you have not set up a test server, an error message will appear instead of the requested website . This technology can also be used to switch off advertisements throughout the system. So that you don't have to make every entry by hand, you can find ready-made and regularly expanded hosts files on the Internet. The hosts file may have Can have a major impact on your safety while surfing the Internet. While the file is well suited to blocking malicious websites, criminals can just as easily use it to post malicious entries. Therefore, you have to make sure that you do not take over entries from other websites without being checked and that no malware makes such entries without your knowledge.