Hosts file and resolv. conf file

Source: Internet
Author: User
Tags domain name server nameserver

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:


# # source server

# # X client host 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 ( 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 is the IP address of the local computer, and is the wrong IP address.

If we write the following content in hosts: # website a to be blocked # 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. localhost #3721 Network Real Name #3721 real-name Network #3721 Network Real Name #3721 Network Real Name #3721 Network Real Name #3721 Network Real Name #3721 Network Real Name #3721 Network Real Name

Example 2.

Add the following content to the hosts file to shield the corresponding URLs defined in the file. localhost # Baidu ie search partner # Baidu ie search partner # Baidu ie search partner

Example 3.

Immune to some viruses

****************** XXX. XXX. XXX. mmma. biz




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:





The most important is the nameserver keyword. If nameserver is not specified, the DNS server cannot be found. Other keywords are optional.

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