Zhihu Answer 1:

In order to facilitate user memory, we change IP addresses into domain names and input them into the browser for access. This makes it necessary to resolve the domain name to IP first when visiting the website. DNS (Domain Name Server) is used for IP resolution and mapping domain names to IP addresses.
Among the five blocking methods of Great FireWall, DNS pollution is a simple and effective method. GFW will interfere with the DNS resolution process, which will return an incorrect IP address to your host for some interfered domain names, making you unable to connect to the server you want to read the correct information correctly.
Hosts file was originally used to improve parsing efficiency. Before making a DNS request, the system will first check whether there is this address mapping relationship in its Hosts file. If there is, it will call this IP address mapping. If no domain name resolution is proposed to the known DNS server. That is to say, the request level of Hosts is higher than that of DNS. When there is a corresponding IP address in your Hosts file, it will access that IP address directly instead of through DNS.
Therefore, when we directly put Google, Twitter, Facebook and other IP addresses into the Hosts file, we can skip the DNS resolution step and directly access the IP addresses, which are free from GFW DNS pollution.

One more thing to add is why the IP address of Hosts should be changed from time to time, and why FB and Twitter will still be unavailable. Because the second big move of GFW is IP blocking. For example, when visiting a foreign IP address, you cannot access it, and ping fails. Tracert finds that all IP addresses are blocked near the edge router (GFW). In other words, GFW directly intercepts packets with this IP header. Therefore, if your changed IP address is blocked, even if you pass the DNS level, you can still not cross GFW.

Zhihu Answer 2:

One of the most accessible metaphors:

Hosts=traditional phone book

DNS (recursive)=operator of traditional directory inquiry desk (e.g. 114)

Target website (domain name)=telephone users (individuals/companies) who need to query their phone numbers

IP corresponding to the target website=phone number of the phone user

If you don't have a phone book (i.e. hosts) on hand (the local machine), you need to call the 114 directory assistance desk (i.e. the DNS on the network) to query the phone number (i.e. the IP address corresponding to the website) of a sensitive user (i.e. the target website). The operator (i.e. recursive DNS) tells you an incorrect number or empty number (i.e. 404) according to the machine room record (the wall pollution pool), so you can't get through.

On the other hand, if you have a phone book (that is, there are hosts files on your computer), you do not need to call the directory assistance desk (DNS). Instead, you can directly find the user (target website) in the phone book (hosts) and dial the corresponding phone number (visit the IP address corresponding to the target website).

Summary: Hosts is the phone book of the network, DNS is the network directory inquiry desk, and 404 is an empty number or an incorrect number. If you have a phone book, you can dial the correct phone number without the directory inquiry desk. --, This is the role of hosts.

Zhihu Answer 3:

Now go to see a doctor. Many hospitals are not allowed to "click" a doctor. They are assigned when they register.

The patient is like the inquirer, the registrar is like DNS, and the doctor is like the server IP to be found.
What's the first thing a doctor does when he comes to work? punch the clock! The registrar knows that the doctor has arrived, and will assign patients to him later! Some registrars get sick, especially some registrars deliberately make mistakes, assign hemorrhoid patients to the stomatology department, disrupt the normal order of medical treatment, and destroy the doctor-patient relationship. I hate such people most! What should I do? If you go to the hospital more often, you will know that a doctor is here every day and can see my disease. Then you will go to the hospital directly to find the doctor! This means that a domain name is "fixed" to an IP address in the host file. If you cross the "registrar", you will not be fooled by the registrar.

This is not without its disadvantages. If the doctor changes his job or sells fruit one day, and you go to the original hospital to find the doctor, your illness will be delayed.

Do you understand after reading the above?