admin管理员组

文章数量:1533918

2024年4月23日发(作者:)

Hosts文件的用途

一. Hosts文件的位置

很多用户都知道在Window系统中有个Hosts文件(没有后缀名),在Windows 98系

统下该文件在Windows文件夹。

在Windows 2000/XP系统中位于%Systemroot%System32DriversEtc 文件夹中,

其中,%Systemroot%指系统安装路径。例如,Windows XP 安装在C:WINDOWS,那么

Hosts文件就在C:WidowsSystem32DrversEtc中。

你也可以用windows自带的查找功能搜索找到hosts文件。

该文件其实是一个纯文本的文件,用普通的文本编辑软件如记事本等都能打开和编辑。

二. Hosts文件的基本内容和语法

用记事本打开hosts文件,就可以看见了微软对这个文件的说明。Hosts文件文一般有

如下面的基本内容

# 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 should be kept on an individual line. The IP address should

# be placed in the first column followed by the corresponding host name.

# The IP address and the host name should 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 # source server

# 38.25.63.10 # x client host

127.0.0.1 localhost

这个文件是根据TCP/IP for Windows 的标准来工作的。它的作用是定义IP地址和

Host name(主机名)的映射关系,是一个映射IP地址和Host name (主机名) 的规定。

这个规定中,要求每段只能包括一个映射关系,也就是一个IP地址和一个与之有映射关系

的主机名。 IP地址要放在每段的最前面,映射的Host name(主机名)在IP后面,中间用空

格分隔。对于这段的映射说明,用“#”分割后用文字说明。

三. Hosts文件的工作方式

现在让我们来看看Hosts在Windows中是怎么工作的。

我们知道在网络上访问网站,要首先通过DNS服务器把要访问的网络域名

()解析成的IP地址后,计算机才能对这个网络域名作访

问。

要是对于每个域名请求我们都要等待域名服务器解析后返回IP信息,这样访问网络的

效率就会降低,因为DNS做域名解析和返回IP都需要时间。

为了提高对经常访问的网络域名的解析效率,可以通过利用Hosts文件中建立域名和

本文标签: 文件域名网络访问IP地址