I. Hosts file location
In Windows 2000/XP/Vista, go to the \ % SystemRoot % \ system32 \ drivers \ etc folder.
Ii. Basic Content and syntax of the hosts file
Open the hosts file in notepad and you will be able to see Microsoft's instructions on 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 shoshould be kept on an individual line. The IP address shold
# Be placed in the first column followed by the corresponding host name.
# The IP address and the host name shocould 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 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.
Iii. How the hosts file works
Now let's take a look at how hosts works in windows.
We know that to access a website on the network, we must first resolve the domain name (xxxx.com) to XXX through the DNS server. xxx. xxx. after the IP address of XXX, 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.
Iv. How the hosts file works and its specific functions
Now let's take a look at how the hosts file works and what roles it plays in specific use.
1. Accelerate domain name resolution
For websites that require frequent access, we can configure the ing between domain names and IP addresses in hosts to improve the domain name resolution speed. Because of the ing relationship, when we enter the domain name computer, we can quickly resolve the IP address, instead of requesting the DNS server on the network.
2. Facilitate LAN users
In the LAN of many organizations, servers are provided for users. However, DNS servers are rarely set up in a LAN. when accessing these servers, you must enter an IP address that is hard to remember. This is troublesome for many people. Now you can give these servers an easy-to-remember name, and then create an IP ing in hosts. In this way, you only need to enter the name of the server for future access.
3. Website Blocking
Many websites install various plug-ins on your computer without your consent. Some of them 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 the Local Computer, so that no access is required. In Windows X, it is agreed that 127.0.0.1 is the IP address of the local computer, and 0.0.0.0 is the wrong IP address.
If we write the following content in hosts:
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 will resolve them to the IP address of the local machine or the wrong IP address, to shield websites A and B.
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.
5. Examples of blocking websites that do not want to access
Here are some examples of using the hosts file to shield some URLs. For more information about how to use the hosts file, see.
Example 1.
Add the following content to the hosts file to shield 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 real-name Network
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
127.0.0.1 www.3721.com #3721 Network Real Name
127.0.0.1 www.3721.net #3721 Network Real Name
Example 2.
Add the following content to the hosts file to shield the corresponding URLs defined in the file.
127.0.0.1 localhost
127.0.0.1 bar.baidu.com # Baidu ie search partner
127.0.0.1 www.baidu.com # Baidu ie search partner
127.0.0.1 Baidu.com # Baidu ie search partner
Example 3.
Immune to some viruses
******************
127.0.0.1 yu.8s7.net
127.0.0.1 1.jopanqc.com
127.0.0.1 2.joppnqq.com
127.0.0.1 wg.47w.com
127.0.0.1 1.joppnqq.com
127.0.0.1 XXX. m111.biz
127.0.0.1 1.jopenqc.com
127.0.0.1 1.jopenkk.com
127.0.0.1 XXX. vh7.biz
127.0.0.1 xxx.j41m.com
127.0.0.1 3.joppnqq.com
127.0.0.1 d.93se.com
127.0.0.1 www.868wg.com
127.0.0.1 XXX. mmma. biz
127.0.0.1 ilove.com
127.0.0.1 tp.shpzhan.cn
127.0.0.1 www.tomwg.com
127.0.0.1 www.cike007.cn
127.0.0.1 www.22aaa.com
127.0.0.1 xx.exiao01.com
127.0.0.1 www.exiao01.com
127.0.0.1 www.exiao01.com
127.0.0.1 new.749571.com
127.0.0.1 xtx.kv8.info
127.0.0.1 cao.kv8.info
127.0.0.1 1.jopmmqq.com
127.0.0.1 171817.171817.com
127.0.0.1 d2.llsging.com
127.0.0.1 down.malasc.cn
127.0.0.1 llboss.com
127.0.0.1 nx.51ylb.cn
127.0.0.1 my.531jx.cn
127.0.0.1 qqq.dzydhx.com
127.0.0.1 qqq.hao1658.com
127.0.0.1 www.333292.com
127.0.0.1 down.18dd.net
127.0.0.1 up.22x44.com
127.0.0.1 aaa.faba01.com
127.0.0.1 bad.tqdlt.cn
127.0.0.1 1.chsipo.com
127.0.0.1 c3.aishangai.net
127.0.0.1 c2.aishangai.net
127.0.0.1 xxx.188dm.com
127.0.0.1 x2.1a2b3c1.com
127.0.0.1 d1.163500.net
127.0.0.1 down.google-serv.cn
******************
******************
127.0.0.1 gxgxy.net 127.0.0.1 c0mo.com
******************
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.
Resolv. conf
This file is a DNS domain name resolution configuration file. Its format is very simple. Each line starts with a keyword, followed by configuration parameters.
Resolv. conf has four keywords:
Nameserver # define the IP address of the DNS server
Domain # define a local domain name
Search # define the domain name search list
Sortlist # Sort the returned domain names
An example of/etc/resolv. conf:
Domain ringkee.com
Search www.ringkee.com ringkee.com
Nameserver 202.96.128.86
Nameserver 202.96.128.166
The most important is the nameserver keyword. If nameserver is not specified, the DNS server cannot be found. Other keywords are optional.