A file named hosts exists in both Linux and Windows systems. It is a text file and can be edited manually.
The role of the hosts file is simple: speed up domain name resolution. it stores some of the most frequently used domain names and IP ing relationships, or domain names or host addresses that are not commonly used but never change the IP address. for example, if the IP address of cnblogs.com never changes, you can write it to the hosts file. If you need to access cnblogs.com later, you no longer need to perform DNS resolution first, however, you can directly find the IP address in the hosts file and directly access it.
The purpose of the hosts file shows that the hosts file can have other functions. for example, if you want to disable access to www.deniedwebsite.com from a local user, you can map it to an invalid IP address in the hosts file, you can also map it to a secure address, such as the cnblogs.com IP address, or even directly map it to the local ip127.0.0.1. so that when you visit that website in the future, as the system detects that the hosts file already has its ing, the system will not allow DNS to perform address resolution, but directly select the specified IP address in the hosts file for access.
The following describes the hosts file format.
The hosts file is a text file, and each address ing occupies one line. The format of each line is as follows:
IP address host or domain name [host alias] [host alias]...
IP addresses and hosts are required. They can be followed by one or more aliases. Separate different fields with one or more spaces (or tabs.
The hosts file can contain comments. The content after line # is ignored by the system as comments.
Generally, the hosts file must contain at least the following content:
127.0.0.1 localhost. localdomain
It means to map localhost to the local machine.
If you do not have this line of content, the system will "do not know localhost. even Ping localhost won't work. if the application calls the system function gethostbyname ("localhost"), it will get a not_found error. of course. because there is no localhost In the hosts file, the system will let the DNS resolve the localhost. The answer should be: the host does not exist.