原文地址:https://my.oschina.net/u/874225/blog/194348html
在操做系统中的路径:
Win7在C:\Windows\System32\drivers\etc目录下windows
内容:包含IP地址和Host name(主机名)的映射关系,是一个映射IP地址和Host name(主机名)的规定;安全
具体工做方式:
在网络上访问网站,要先经过DNS服务器把网络域名解析成IP地址后,咱们的计算机才能访问。要是对于每一个域名请求咱们都要等待域名服务器解析后返回IP信息,这样访问网络的效率就会下降,而Hosts文件就能提升解析效率。根据Windows系统规定,Hosts的请求级别比DNS高。在进行DNS请求之前,Windows系统会先检查本身的Hosts文件中是否有这个地址映射关系,若是有则调用这个IP地址映射,若是没有再向已知的DNS服务器提出域名解析。服务器
hosts文件内容大体以下:网络
# Copyright (c) 1993-2009 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
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhostapp