Functions of Hosts files in Windows

Source: Internet
Author: User
Tags domain name server
In common applications, we will inevitably encounter some usage of the Hosts file. The following analysis shows that if there is anything wrong, I hope to correct it.
In Windows, there is a Hosts file (without a suffix). in windows 98, this file is located in the Windows directory. in 2 K/XP, the file is located in the % systemroot % \ system32 \ drives \ etc directory. this file is a plain text file and can be opened in a common text editor (such as NotePad). After opening it, we can see Microsoft's description of this file.

# 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

Translation:
This is a file that works according to Microsoft TCP/IP for windows standards.
This file contains the ing between the IP address and HOST name (HOST name). (In this file) each entry should own one row.
The IP address should be placed first, followed by the Host name. The IP address and Host name should be at least one
Separated by spaces.
Note (as we can see just now) should be inserted to another row, or separated by "#" after the machine name.

------ The above is the explanation. Let's take a look at the working principle.



When accessing a website on the network, we must first resolve the network domain name (www.xxx.com) to an IP address through the DNS server so that our computer can access the website. if the IP address is returned after each domain name resolution request is resolved by the Domain Name Server, the network access efficiency will be reduced. the Hosts file can improve the resolution efficiency.

According to Windows System regulations, before a DNS request is made, the system checks whether the geological ing relationship exists in the Hosts file. if yes, the IP address ing is called directly. if no DNS exists, the DNS server is resolved to a known DNS server. that is to say:

Hosts request level is higher than DNS

After learning how it works, let's see how it works in practice?


1. Accelerate domain name resolution
For frequently accessed addresses, We can configure the ing between IP addresses and network domain names so that when we access a website and enter a domain name, the computer can quickly resolve the IP address, instead of requesting DNS servers on the network

2. Facilitate LAN users
In many public scenarios, servers are provided to users, but DNS servers are rarely assumed in the LAN. to access these servers, remember and enter hard-to-remember IP addresses. This is quite troublesome for many people. now you can give these servers an easy-to-remember name, in the form of a network domain name, and then create an IP ing in Hosts, so that you can enter the server name in the future access.

3. Website Blocking
Nowadays, many websites install various plug-ins on the computer without the user's consent. Some may be virus. for these websites, we can use Hosts to map the website domain name to the wrong IP address or the IP address of our computer, so that no access is required.
127.0.0.1 # websites to be blocked
0.0.0.0 # websites to be blocked
In this way, the computer resolves the domain name to an error or the IP address of the Local Machine, thus blocking the domain name.

4. Smooth system connection
For Lotus servers and some database servers, if you enter an IP address directly during access, the access is not allowed only by entering the server name. then we configure the Hosts file so that the server name can be accessed smoothly.


Finally, it is pointed out that the hosting of the Hosts file configuration is static. If the IP address of the network computer is changed, the IP address must be updated in time; otherwise, the IP address cannot be accessed.

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.