Hosts文件是一个用于存储计算机网络中节点信息的文件,它可以将主机名映射到相应的IP地址,实现DNS的功能,它可以由计算机的用户进行控制。
Hosts文件的存储位置在不同的操作系统中并不相同,甚至不同Windows版本的位置也不大一样:
Windows NT/2000/XP/2003/Vista/win7:默认位置
为%SystemRoot%\\system32\\drivers\\etc\\,但也可以改变。
例如 c:\\windows\\system32\\drivers\\etc\\
动态目录由注册表键\\HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\ Services\\Tcpip\\Parameters\\DataBasePath决定。
Windows 95/98/Me:%WinDir%\\
用记事本打开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 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost
这个文件是根据TCP/IP for Windows 的标准来工作的。它的作用是定义IP地址和
Host name(主机名)的映射关系,是一个映射IP地址和Host name (主机名) 的规定。这个规定中,要求每段只能包括一个映射关系,也就是一个IP地址和一个与之有映射关系的主机名。 IP地址要放在每段的最前面,映射的Host name(主机名)在IP后面,中间用空格分隔。对于这段的映射说明,用“#”分割后用文字说明。