How the hosts file works under Windows

Hosts file principle analysis

hosts
First, under, hosts file without a suffix
a. The location of the Hosts file
, many users are aware there is a Hosts file (no extension) in the Window System, in the Windows 98 system files in the Windows folder.
In the Windows 2000 / XP system, it is located in the \% Systemroot% \ System32 \ Drivers \ Etc folder, where% Systemroot% refers to the system installation path. For example, if Windows XP is installed in C: \ WINDOWS, then the Hosts file is in C: \ Widows \ System32 \ Drvers \ Etc.
You can also use the search function that comes with Windows to search and find the hosts file.
The file is actually a plain text file, which can be opened and edited with ordinary text editing software such as Notepad.

two. Hosts file content and basic grammar
use Notepad to open the hosts file, you can see Microsoft's description of this file. Hosts file text 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


这个文件是根据TCP/IP for Windows 的标准来工作的。它的作用是定义IP地址和
The mapping relationship of Host name is a provision for mapping IP address and Host name. This rule requires that each segment can only include one mapping relationship, that is, an IP address and a host name that has a mapping relationship with it. The IP address should be placed at the forefront of each segment, the mapped Host name (host name) after the IP, separated by spaces. For the mapping description of this paragraph, use "#" to separate it and use text to explain.

three. Hosts file works
now let's look at Windows Hosts is how it works.
We know that to access a website on the Internet, we must first resolve the network domain name (XXXX.com) to the IP address of XXX.XXX.XXX.XXX through the DNS server, and then the computer can access this network domain name.
If for each domain name request we have to wait for the domain name server to resolve and return IP information, the efficiency of accessing the network will be reduced, because DNS takes time to do domain name resolution and return IP.
In order to improve the efficiency of resolving frequently accessed network domain names, you can use the Hosts file to establish the mapping between domain names and IP to achieve the goal. According to the Windows system regulations, before making a DNS request, the Windows system will first check whether there is this network domain name mapping relationship in its Hosts file. If so, call this IP address mapping, if not, then propose domain name resolution to a known DNS server. In other words, the request level of Hosts is higher than that of DNS.

four. Hosts file works and the specific role
now look at the work of the Hosts file and what role it plays in the specific use.

1, speed up DNS

for the site to be frequently accessed, we can configure the mapping between domain names and IP in the Hosts, increasing the speed of domain name resolution. Because of the mapping relationship, when we enter the domain name computer, we can quickly resolve the IP without requesting a DNS server on the network.

2. Convenient for LAN users

In many organizations' local area networks, there will be servers for users to use. However, since DNS servers are rarely set up in LANs, when accessing these servers, enter an IP address that is difficult to remember. This is quite troublesome for many people. Now you can give these servers a name that is easy to remember, and then establish an IP mapping in Hosts, so that when you visit later, you only need to enter the name of the server.

3, blocked sites

now there are many sites without the user's consent will be a variety of plug-in installed on your computer, some of which maybe is the Trojan horse or virus. 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 there is no need to visit. In the WINDOWSX system, 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:

127.0.0.1 # Website A

to be blocked 0.0.0.0 # Website B to be blocked In

this way, when the computer resolves domain names A and B, it resolves to the local IP or the wrong IP To achieve the purpose of blocking websites A and B.

4, smooth connection system

for the Lotus server and some database servers, when accessed directly enter the IP address if it is not accessible, you can only enter the server name to access. Then we configure the Hosts file so that the server name can be entered to connect successfully.

Fives. Examples of shielding unwanted websites
Here are some tips to use the Hosts file to collect some examples of URL blocking, we were learning to use the Hosts file reference.

Example 1.
Add the following content to the hosts file to block the corresponding URL 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 # 3721 Network real name
127.0.0.1 download.3721.net # 3721 Network real name
 
http://blog.csdn.net/perfumekristy/article/details/6839397

Guess you like

Origin www.cnblogs.com/renjiaqi/p/12679549.html