Hosts native DNS domain name resolution

Source: Internet
Author: User
Tags domain name server

A Location of the Hosts file
Many users know that there is a Hosts file (no suffix name) in the Windows system, and that the file is in the Windows folder under the Window 98 system.
In a Windows 2000/XP system located in the \%systemroot%\system32\drivers\etc folder, where%Systemroot% refers to the system installation path. For example, Windows XP is installed in C:\WINDOWS, then the Hosts file is in C:\WINDOWS\system32\drivers\etc.
You can also find the Hosts file using the search feature that comes with Windows.
The file is actually a plain text file that can be opened and edited with ordinary text editing software such as Notepad.

Two The basic content and syntax of the Hosts file
Open the Hosts file with Notepad and you'll see Microsoft's description of the file. The Hosts file generally resembles the following basic content

# Copyright (c) 1993-1999 Microsoft Corp.
#
# This was a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings for IP addresses to host names. each
# entry should is kept on a individual line. The IP address should
# is placed in the first column followed by the corresponding host name.
# The IP address and the host name should is separated by at least one
# space.
#
# Additionally, comments (such as these) may is 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. Its role is to define the IP address and
The mapping of host name (hostname) is a rule that maps the IP address and host name (hostname). This requirement requires that each segment contain only one mapping relationship, that is, an IP address and a host name that has a mapping relationship. The IP address should be placed at the front of each paragraph, the mapped host name (hostname) behind the IP, separated by a space. For this section of the mapping instructions, with "#" after the split with the text description.

Three How the Hosts file works
Now let's look at how the hosts work in Windows.
We know that access to the Web site on the network, the first through the DNS server to access the network domain name (xxxx.com) to resolve to XXX.XXX.XXX.XXX IP address, the computer can access the network domain name.
For each domain request we have to wait for the domain name server to return the IP information, so that the efficiency of access to the network will be reduced, because DNS to do domain name resolution and return IP will take time.
In order to improve the resolution efficiency of the frequently accessed network domain name, we can achieve the goal by using the mapping relation of the domain name and IP in the hosts file. According to the Windows system, before a DNS request is made, the Windows system first checks to see if the network domain name Mapping is in its own hosts file. If so, call this IP address mapping, and if not, present the domain name resolution to the known DNS server. This means that the hosts request level is higher than DNS.

Four How the Hosts file works and what the specific role
Now look at how the Hosts file works and what it does in use.

1, speed up the domain name resolution

For frequently visited sites, we can improve the speed of domain name resolution by configuring the mapping of domain names and IPs in the hosts. Because of the mapping, when we enter the domain name computer can quickly resolve the IP, instead of requesting a DNS server on the network.

2. Convenient for local area network users

In many units of the local area network, there will be servers available to users. However, because the local area network generally rarely set up a DNS server, access to these servers, to enter the hard-to-remember IP address. This is rather troublesome for many people. It is now possible to give these servers an easy-to-remember name, and then set up an IP map in the hosts so that you can simply enter the name of the server when you access it later.

3. Blocking Websites

Now there are many websites without user consent to install a variety of plug-ins to your computer, some of which may be Trojan or virus. For these sites we can use the hosts to map the site's domain name to the wrong IP or local computer's IP, so that it does not have access. In the WINDOWSX system, the contract 127.0.0.1 is the IP address of the local computer, and 0.0.0.0 is the wrong IP address.
If, in the hosts, we write the following:

127.0.0.1 # sites to block a

0.0.0.0 # sites to block B

In this way, when the computer resolves the domain A and b, it resolves to the native IP or the wrong IP, and achieves the purpose of masking sites A and B.

4. Smooth Connection System

For Lotus servers and some database servers, if you enter the IP address directly when you access that is inaccessible, you can only enter the server name to access. Then we configure the hosts file so that the input server name can be successfully connected.

Five Example of blocking websites you don't want to visit
Here is a collection of some of the use of the Hosts file to screen some of the Web site examples, a total of learning to use the Hosts file reference.

Example 1.
Include the following in 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网络实名
127.0.0.1 3721.net #3721网络实名
127.0.0.1 cnsmin.3721.com #3721网络实名
127.0.0.1 cnsmin.3721.net #3721网络实名
127.0.0.1 download.3721.com #3721网络实名
127.0.0.1 download.3721.net #3721网络实名
127.0.0.1 www.3721.com #3721网络实名
127.0.0.1 www.3721.net #3721网络实名

Example 2.
Include the following in the Hosts file to block the corresponding URLs defined in the file.
127.0.0.1 localhost
127.0.0.1 bar.baidu.com #百度IE搜索伴侣
127.0.0.1

Hosts native DNS domain name resolution

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.