A very comprehensive explanation of the Hosts file,

Source: Internet
Author: User

A very comprehensive explanation of the Hosts file,

It is strange that many people do not know what Hosts is. Today, with the prevalence of Network viruses, it is actually very useful to know Hosts, because many web Trojans are eyeing this file, and in many cases, you only need to open the file and make a small modification to solve the problems you think are very difficult.

1. Address of the Hosts file

Vista, Xp, 2000, and 2003 systems: in the C: \ windows \ system32 \ drivers \ etc folder.
Windows 9x and Me systems: in the C: \ Windows folder.

2. Open Method

This file is actually a plain text file, which can be opened and edited using common text editing software such as Notepad and wordpad. Note that you must save the file after modification.

3. Hosts file function 3.1 accelerate domain name resolution

For websites that require frequent access, we can configure the ing between the domain name and IP address in Hosts so that when we enter the domain name, the computer can quickly resolve the IP address, instead of requesting DNS servers on the network.

3.2 convenient for LAN users

In the LAN of many organizations, servers are provided for users. However, because DNS servers are rarely set up in Lan, it is quite troublesome for many people to access these services to enter hard-to-remember IP addresses. Now we can give these servers an easy-to-remember name, and then create an IP ing in Hosts. In this way, we can enter the name of this server for future access.

3.3 shield websites

Many websites install various plug-ins on your computer without your consent. Some may be Trojans or viruses. For these websites, we can use Hosts to map the Domain Name of the website to the wrong IP address or the IP address of our computer, so that no access is required. For example, if you do not want to access www.xxxx.com, write the following content in Hosts:
127.0.0.1 www.baidu.com # blocked website-this is resolved to the local machine. Errors will occur when Baidu is opened.
0.0.0.0 www.baidu.com # blocked website-this is resolved to the wrong IP Address
In this way, the computer will resolve the domain name to the local IP address or the wrong IP address, to achieve the purpose of blocking.

3.4 smooth system connection

For Lotus servers and some database servers, if you enter an IP address directly during access, it cannot be accessed. You can only enter the server name to access the server. Then we configure the Hosts file so that the server name can be successfully connected.
Finally, it should be pointed out that the hosting configured in the Hosts file is static. If the computer on the network changes, update the IP address in time; otherwise, the IP address cannot be accessed.

3.5 forcibly specify the basic content and syntax of a domain name corresponding to an IP address 4. Hosts file

Open the hosts file in notepad and you will be able to see Microsoft's instructions on this file. Generally, the Hosts file contains the following basic content:

 1   # Copyright (c) 1993-1999 Microsoft Corp. 2   # 3   # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. 4   # 5   # This file contains the mappings of IP addresses to host names. Each 6   # entry should be kept on an individual line. The IP address should 7   # be placed in the first column followed by the corresponding host name. 8   # The IP address and the host name should be separated by at least one 9   # space.10   #11   # Additionally, comments (such as these) may be inserted on individual12   # lines or following the machine name denoted by a '#' symbol.13   #14   # For example:15   #16   # 102.54.94.97 rhino.acme.com # source server17   # 38.25.63.10 x.acme.com # x client host

127.0.0.1 localhost #127.0.0.1 is the local ip Address

This file works according to TCP/IP for Windows standards. It defines IP addresses and
Host name (Host name) ing is a ing between the IP address and Host name (Host name. In this provision, each segment must contain only one ing relationship, that is, an IP address and a host name mapped to it.
The IP address must be placed at the beginning of each segment, and the mapped Host name (Host name) must be placed behind the IP address, separated by spaces. For this section of ing description, use "#" to separate and then use text description.
For example, 72.14.219.190 www.baidu.com resolves the domain name www.baidu.com to the IP address 72.14.219.190.
Note: Do not have spaces before the IP address. There must be at least one space between the IP address and the domain name.

5. How the Hosts file works

We know that to access a website on the network, you must first resolve the domain name (such as baidu.com) to the IP address of baidu.com through the DNS server before the computer can access this network domain name.
For each domain name request, we have to wait for the Domain Name Server to resolve and return the IP address information. This will reduce the network access efficiency, because it takes time for DNS to resolve the domain name and return the IP address.
To improve the resolution efficiency of frequently accessed network domain names, you can use the Hosts file to establish a ing between domain names and IP addresses. According to Windows System regulations, before a DNS request is made, Windows system will first check whether the network domain name ing relationship exists in your Hosts file. If yes, the IP address ing is called. If no, domain name resolution is submitted to the known DNS server. That is to say, the request level of Hosts is higher than that of DNS. This is why many web Trojans like this file.
Here are some examples of using the Hosts file to shield some URLs. For more information about how to use the Hosts file, see.

6. Example

Add the following content to the hosts file to shield the corresponding URLs defined in the file (actually, the domain name is resolved to the local machine to prevent remote connection of Trojan viruses ).

1 127.0.0.1 localhost2 127.0.0.1 download.3721.com3 127.0.0.1 3721.com #3721 Network Real Name
7. Do you know how to obtain the IP address corresponding to the domain name?

Open "start-run", enter "cmd", enter "ping www.baidu.com" on the command line interface, and press Enter.
The displayed result is similar to: Reply from 220.181.6.18: bytes = 32 time = 24 msTTL = 55.
220.181.6.18 is the IP address of the domain name (Baidu ).

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.