The working principle and function of the Hosts file in the operating system and its detailed introduction

  

First, what is the Hosts file?

Hosts is a system file with no extension. The Hosts file is a file for storing node information in a computer network. It can map host names to corresponding IP addresses and implement DNS functions. Controlled by the user of the computer. It can be opened with a tool such as Notepad. Its function is to associate some commonly used URL domain names with their corresponding IP addresses. “Database”, when the user enters a URL that needs to be logged in in the browser, the system will automatically start from Look for the corresponding IP address in the Hosts file. Once found, the system will immediately open the corresponding web page. If it is not found, the system will submit the URL to the DNS domain name resolution server for IP address resolution.

The storage location of the Hosts file is not the same in different operating systems, even the location of different Windows versions is not the same:

Windows NT/2000/XP/2003/Vista/win7 : The default location is %SystemRoot%\\system32\\drivers\\etc\\, but you can also change the location of the hosts file:

Location of the Windows XP system: C:\\WINDOWS\\system32\\drivers\\etc

hosts File contents:
Copy code
The code is as follows: # Copyright (c) 1993-1999 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This The IP address to host names. Each # entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be Separated by at least one# space.## Additionally, comments (such as these) may be inserted on individual# lines or following the machine name by d a '#' symbol.## For example:## 102.54.94.97 rhino. Acme.com # source server# 38.25.63.10 x.acm E.com # x client host127.0.0.1 localhost

Second, how the Hosts file works

We know that to access the website on the network, we must first access the network domain name through the DNS server. After (XXXX.com) resolves to the IP address of XXX.XXX.XXX.XXX, the computer can access the domain name.

If we wait for the domain name server to parse and return IP information for each domain name request, the efficiency of accessing the network will be reduced, because it takes time for DNS to do domain name resolution and return IP. To improve the resolution of frequently accessed network domain names, you can achieve the purpose by establishing a mapping between domain names and IPs in the Hosts file. According to the Windows system, before the DNS request is made, the Windows system first checks whether there is a mapping relationship between the network domain names in its Hosts file. If there is, call this IP address mapping, if not, then propose domain name resolution to the known DNS server. In other words, the request level of Hosts is higher than DNS.

Three, the specific role of the Hosts file

1, speed up the domain name resolution

For websites that need to be visited frequently, we can configure the mapping between domain name and IP in Hosts. Improve the speed of domain name resolution. Thanks to the mapping, when we enter the domain name computer, we can quickly resolve the IP without requesting a DNS server on the network. It should be noted that the mapping of the Hosts file configuration is static. If the computer on the network changes, please update the IP address in time, otherwise it will not be accessible.

2. Convenient LAN users

In many local area networks, there will be servers available to users. However, since the DNS server is rarely set up in the local area network, when accessing these servers, it is necessary to input a hard-to-remember IP address. This is quite troublesome for many people. Now you can give these servers a name that is easy to remember, and then create an IP mapping in Hosts, so that when you access it later, just enter the name of the server.

3. Shielding Websites

There are many websites that install a variety of plugins into your computer without the user's consent, some of which may be Trojans or viruses. For these sites we can use Hosts to map the domain name of the site to the wrong IP or IP of the local computer, so there is no need to access it. In the WINDOWSX system, the agreement 127.0.0.1 is the IP address of the local computer, and 0.0.0.0 is the wrong IP address.

If, in Hosts, write the following:
Copy the code
The code is as follows: 127.0.0.1 www.XXXX.com #Shielded website A0.0.0.0 www .XXXX.com #Shielded Website B. When the computer resolves the domain names A and B, it resolves to the local IP or the wrong IP, and achieves the purpose of blocking websites A and B.

4. Smooth connection system

For Lotus servers and some database servers, if you directly enter the IP address during access, you can't access it. You can only enter the server name to access it. Then we configure the Hosts file so that the server name can be successfully connected.

Four, how to manually kill and kill the HOSTS table virus

If you suspect that your hosts file is modified by the virus Trojan, you can copy the above content to repair the hosts file. However, the fundamental measure is to find and delete the virus files in the system. Here are the repair steps:

You must first enter safe mode. Secondly, run regedit to delete the following items. There are many possibilities behind HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run. Currently, there are 2 kinds! The name is R or A1.R=C:\\Windows\\System32\ undll32.exe ctfmon.dll s2.A=C:\\WINDOWS\\system32\ undll32.exe msad.dll s If you find one of these 2, directly Delete this item. Then find C:\\Windows\\System32\\ctfmon.dll or C:\\Windows\\System32\\msad.dll to delete the file to repair the HOSTS file (in fact, the installation of 360 security guards in safe mode can be repaired, here said manual repair Method) Please operate as follows:

1. Search the hosts file in the system, or you can find it according to the following path:
Copy the code
The code is as follows: Windows 98 system, file path \\Windows directory; Windows XP system, file path \\Windows\\System32\\Drivers\\Etc directory; Windows 2000 system, file path: WINNT\\System32\\Drivers\\Etc directory; WIN7 system, file path: WINNT\\System32\\Drivers \\Etc directory 2. First backup this file; 3. Right click on the hosts file, select {Open Mode}, select Notepad; 4. Delete the contents of Notepad, or simply delete the hosts file! (Does not affect the normal use of the system) Note: Please do not directly modify the text tool such as Notepad UltraEdit and other professional editors will not cause garbled and other issues.

Copyright © Windows knowledge All Rights Reserved