The working principle and application of the host file

The working principle and application of the host file

The Hosts file is a file used to store the node information in the computer network. It can map the host name to the corresponding IP address and realize the function of DNS. It can be controlled by the user of the computer.

First, the basic introduction of the Hosts file

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

  Windows NT/2000/XP/2003/Vista/win7: The default location is %SystemRoot%\system32\drivers\etc\, but it can be changed. 

  For example c:\windows\system32\drivers\etc\ 

   The dynamic directory is determined by the registry key \ HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet\ Services\Tcpip\Parameters\DataBasePath. 

  Windows 95/98/Me:%WinDir%\ 

  Open the hosts file with Notepad , and you can see Microsoft 's description of this file. The Hosts file generally has the following basic content 

# Copyright (c) 1993-1999 Microsoft Corp. 

  # 

  # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. 

  # 

  # This file contains the mappings of IP addresses 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 denoted by a '#' symbol. 

  # 

  # For example: 

  # 

  # 102.54.94.97 rhino.acme.com # source server 

  # 38.25.63.10 x.acme.com # x client host 

  127.0.0.1  localhost 

This file works according to the TCP/IP for Windows standard. Its function is to define the mapping relationship between IP address and Host name (host name), which is a regulation for mapping IP address and Host name (host name). In this regulation, each segment is required to include only one mapping relationship, that is, an IP address and a hostname that has a mapping relationship with it. The IP address should be placed at the top of each segment, and the mapped Host name should be behind the IP, separated by spaces. For the mapping description of this paragraph, use "#" to delimit it with text description.

2. How the Hosts file works

  Now let's see how Hosts work in Windows. 

  We know that to access a website on the Internet, you must first resolve the network domain name (XXXX.com) to be accessed into the IP address of XXX.XXX.XXX.XXX through the DNS server , and then the computer can access this network domain name. If we have to wait for the domain name server to resolve 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. 

  In order to improve the resolution efficiency of frequently accessed network domain names, the mapping relationship between domain names and IPs can be established by using the Hosts file to achieve the purpose. According to the regulations of the Windows system, before making a DNS request, the Windows system will first check whether there is this network domain name mapping relationship in its own Hosts file. If so, call this IP address mapping, if not, then propose domain name resolution to a known DNS server. That is to say, the request level of Hosts is higher than that of DNS. 

3. How the Hosts file works and its specific role

  Now let's take a look at how the Hosts file works and what role it plays in specific usage. 

1. Speed ​​up domain name resolution

  For frequently visited websites, we can improve the domain name resolution speed by configuring the mapping relationship between domain names and IPs in Hosts. Due to the mapping relationship, when we enter the domain name, the computer can quickly resolve the IP without requesting the DNS server on the network. 

2. Convenient for LAN users

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

3. Block websites

  There are now many websites that install various plug-ins into your computer without the user's consent, some of which may be Trojan horses or viruses. For these websites, we can use Hosts to map the domain name of the website to the wrong IP or the IP of the local computer, so that we don't have to visit. In the WINDOWSX system, the convention 127.0.0.1 is the IP address of the local computer, and 0.0.0.0 is the wrong IP address. 

  If, we are in Hosts, write the following: 

  127.0.0.1 www.XXXX.com #blocked website A 

  0.0.0.0 www.XXXX.com #blocked website B 

  In this way, when the computer resolves the domain names A and B, it resolves to the local IP or the wrong IP, thus achieving the purpose of shielding the websites A and B. 

4. Smooth connection to the system

  For Lotus servers and some database servers , if you directly enter the IP address when accessing, you cannot access it, you can only access it by entering the server name. Then we configure the Hosts file so that we can connect successfully by entering the server name. 

5. Examples of blocking unwanted websites

  Here are some collected examples of using the Hosts file to block some URLs for reference when you learn to use the Hosts file. 

  Example 1. 

  Add the following content to the hosts file to block the corresponding URLs defined in the file. 

  127.0.0.1 localhost 

  127.0.0.1 download.3721.com 

  127.0.0.1 3721.com #3721 Network real name 

  127.0.0.1 3721.net #3721 Network real name 

  127.0.0.1 cnsmin.3721.com #3721 Network real name 

  127.0.0.1 cnsmin.3721.net #3721 Network real name 

  127.0.0.1 download.3721.com #3721Network real name 

  127.0.0.1 download.3721.net #3721Network real name 

  127.0.0.1 www.3721.com #3721 Internet real name 

  127.0.0.1 www.3721.net #3721Network real name 

  Example 2. 

  Add the following content to the hosts file to block the corresponding URLs defined in the file. 

  127.0.0.1 localhost 

  127.0.0.1 bar.baidu.com #Baidu IE search companion 

  127.0.0.1 www.baidu.com #Baidu IE search companion 

  127.0.0.1  baidu.com #Baidu  IE search companion 

  Finally, it should be pointed out that the mapping configured in the Hosts file is static. If the computer on the network changes, please update the IP address in time, otherwise it will not be accessible. 

Fourth, how to manually kill the virus that hijacks the HOSTS table

  First you have to enter safe mode 

  Next, run regedit to delete the following items, find HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run 

  There are many possibilities in the back, and there are currently 2 types! named R or A 

  1.R=C:\Windows\System32\rundll32.exe ctfmon.dll s 

  2.A=C:\WINDOWS\system32\rundll32.exe msad.dll s 

  If you find one of these two, delete this item directly. 

  Then find C:\Windows\System32\ctfmon.dll or C:\Windows\System32\msad.dll 

  delete the file 

  To repair the HOSTS file (in fact, it can be repaired by installing and running 360 Security Guard in safe mode, here is the 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: 

  Windows 98 system, under the file path\Windows directory; 

  Windows XP system, the 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 the hosts file, select {Open with}, and select Notepad; 

  4. Delete the contents of Notepad, or simply delete the hosts file! (Does not affect the normal use of the system)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324683835&siteId=291194637