原文地址: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