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 system32driversetchosts; 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:
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.