Hosts file (function and modification of hosts file)
What is 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 find the corresponding IP address from the hosts file. Once found, the system will open the corresponding web page immediately. If not, 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, since DNS servers are rarely set up in the local area network, when accessing these servers, Youyou.com needs 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. Youyou.com 3 blocks spam sites
Now there are many websites that install various plug-ins, including viruses and Trojan horses, on our computers without our consent. 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 of Youyou.com, 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 is established in the hosts fileThe mapping relationship with Baidu 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