Functions of the hosts file

Source: Internet
Author: User
Tags domain name server

Today, I wanted to open all the Gmail results, but then I opened www.google.com To Go To The Baidu homepage... Dizzy

Then I found the reason why the original hosts file was changed, and Yahoo and Google were all resolved to the Baidu address...

Hosts file explanation

This file works according to TCP/IP for Windows standards. Its role is to include IP addresses and host names.
Host Name ing, which is a ing between the IP address and Host Name
The host name requirement requires that each segment only contain one ing relationship. The IP address should be placed at the beginning of each segment, and the mapped host name should be written after spaces.
Host Name. For this section of the ing description, use "#" to separate and then use text description.

In Windows
In 2000, the hosts file is located in the C:/winnt/system32/Drivers/etc folder. The downloaded hosts file shields some malicious code (such
May modify your home page, registry, install Trojan programs, advertisements, etc. After downloading and decompressing the package, replace the files in C:/winnt/system32/Drivers/etc.
Yes. In the Win98 system, you must change the decompressed file name to hosts. Sam.

In Windows XP, the hosts file is located in the C:/Windows/system32/Drivers/etc folder. The operation is similar.

To open hosts, choose Start> RUN> % SystemRoot %/system32/Drivers/etc. Select hosts and open it in notepad.

Localhost local ing.

Function

Windows has a hosts file (without a suffix). in Windows 98, the file is in the Windows directory and in Windows
In the 2000/XP system, C:/winnt/system32/Drivers/etc
Directory. This file is actually a plain text file, which can be opened using common text editing software such as Notepad.

Open the hosts file in Notepad. First, you can see Microsoft's description of this file. This file is based on TCP/IP for Windows
It is used to map IP addresses and host names.
The name (host name) rule requires that each segment can only contain one ing relationship, the IP address should be placed at the beginning of each segment, and then write the mapped host
Name (host name ). For this section of the ing description, use "#" to separate and then use text description.

Now let's take a look at how hosts works in windows.

We know that to access a website on the network, we need to first resolve the network domain name (www.xxxx.com) to the IP address of 61. XXX through the DNS server, after our calculation
Machine to access. For each domain name request, we need to wait for the Domain Name Server to return IP information after resolution, so that the network access efficiency will be reduced, and the hosts file can improve the resolution efficiency. According
Windows requires that, before a DNS request is made, Windows system will first check whether the address ing relationship exists in its hosts file. If yes, this
IP address ing. If no domain name resolution is provided to a known DNS server. That is to say, the request level of hosts is higher than that of DNS.

What is the role of the hosts file in actual use?

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 computer, we can quickly resolve the IP address, instead of requesting DNS servers on the network.

2. Facilitate 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. Website Blocking

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 names of the website.
To the wrong IP address or the IP address of your computer. For example, if you do not want to access www.xxxx.com, write the following content in hosts:

127.0.0.1 www.xxxx.com # blocked websites
0.0.0.0 www.xxxx.com # blocked website

In this way, the computer resolves the domain name to the local machine or the wrong IP address, to achieve the purpose of blocking.

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, 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.

Attachment: host file 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

 

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.