Windows下hosts文件的做用

原文地址: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服务器提出域名解析。服务器

做用: 
1.加快域名解析; 
2.方便局域网用户--访问时局域网内服务器时,只需输入这个服务器的名字; 
3.屏蔽网站--经过把不想访问的网站的域名映射到错误的IP;
 
[html]  view plain  copy
  1. 在修改HOSTS文件时候,常遇到修改保存后无效的状况,这里要提醒你们注意的一点:不少人是写在最后行,写完最后一行后在没有回车的状况下,这一行是不生效的。必定要记得回车。     
  2. 建议你们遵循这样的习惯:“ip地址+空格+域名+回车” 添加记录。     
  3. 遇到VISTA 或者 windows 7 操做系统没法打开和编辑的状况,提示:“不能建立文件” 或者 “文件操做失败”等提示,  
  4. 是由于安全机制UAC形成的,你可使用如下方法解决:     
  5. 1.在“开始”菜单 ->“搜索”中输入notepad ,  
  6. 而后使用Ctrl+Shift+Enter快捷键便可调用具备系统管理员权限的“记事本”编辑器。     
  7. 2.在“开始”菜单中单击“全部程序”,单击“附件”,右键单击“记事本”,而后单击“以管理员身份运行”。     
  8. 3.打开HOSTS 文件所在位置进行编辑保存。  

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

相关文章
相关标签/搜索