Hosts local DNS domain name resolution

Source: Internet
Author: User
Tags domain name server

I. Hosts file location
Many users know that there is a hosts file in the window system (without a suffix). in Windows 98, this file is in the Windows folder.
In the \ % SystemRoot % \ system32 \ drivers \ etc folder on Windows 2000/XP, % SystemRoot % indicates the system installation path. For example, if Windows XP is installed in c: \ windows, the hosts file is in c: \ windows \ system32 \ drivers \ etc.
You can also search for the hosts file using the search function provided by windows.
This file is actually a plain text file, which can be opened and edited using common text editing software such as Notepad.

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 quite 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

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 host cannot be accessed.

Cool Network (http://www.kuiu.cn /)

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.