Hosts file (method of hosts file)
1 What is a hosts file?
Hosts is a system file without an extension. Its basic function is to establish an associated “database” between some commonly used website domain names and their corresponding IP addresses. When the user enters the URL that needs to be logged in in the browser, the system will first automatically search for the corresponding IP address from the hosts file. Once found, the system will immediately open the corresponding web page, Youyou. If not found, the system will submit the URL to the DNS domain name resolution server for IP address resolution.
2 The role of the host file
2.1 Speed up domain name resolution
For frequently visited websites, we can configure the mapping relationship between domain name and ip in the hosts file, Improve the resolution speed of domain names. Because of the mapping relationship, when we enter a domain name, the computer can quickly resolve the ip address without requesting the DNS server on ***.
2.2 Establish a mapping relationship
Many units have their own local area network and provide different servers to company members. However, DNS servers are rarely set up in the LAN, so when accessing these servers, you need to enter IP addresses that are difficult to remember, which is quite troublesome for everyone. So we can give each of these servers an easy-to-remember name, and then set up IP mapping in the hosts file, so that when accessing later, just enter the name of this server and it will be OK!
3.3 Block spam sites
Now there are many websites that install various plug-ins Anyyouyou resources into our computers without our consent, including viruses and Trojan horses. For these websites, we can use the hosts file to map the domain name of these websites to a wrong IP or the IP address of the local computer, so that the purpose of prohibiting access can be achieved!
4 ways to modify the hosts file
Because the hosts file is a system file, you need administrator privileges to modify it.
One method: first modify the authority to administrator authority, and then modify it.
The second method: first copy the hosts file to the desktop, and then you can modify it without administrator privileges. After modification, drag it back to the original directory and replace it!
In the iOS system, the location of the hosts file is: ~/private/etc.
On the Windows system, the location of the hosts file is: c:\Windows\system32\drivers\etc.
Example of host file modification:
202.108.22.5·www.baidu.com
One
As shown above, we are locally The Baidu IP address and Baidu IP address are established in the hosts file.The mapping relationship of the domain name plays the role of “speeding up domain name resolution”, because there is no need to request the DNS server anymore! Also, if we want to comment on it, just add a # sign in front of it, for example:
# 202 . 108 . 22 . 5 www.baidu.com