分享

hosts文件配置

 dmw_zgl 2015-01-09

    hosts文件位于" C:\Windows\System32\drivers\etc "目录下,用于转换名字与IP地址的转换。

    在浏览器中通过域名访问网站,首先查看hosts文件中是否存在域名与IP的地址转换,如果存在则直接根据IP地址进行访问;否则向DNS服务器发送请求,根据返回结果中的IP进行访问。

    那么hosts文件带来了哪些用途呢?

1. 提升了网站的访问速度

    如果在hosts中配置了常用的网址和IP的映射关系,就省去了向DNS服务器发送请求获取IP的过程,从而更快的访问网站速度。

2. 屏蔽网站

    在hosts文件中添加

  1. 127.0.0.1 www.baidu.com  

    则访问 "www.baidu.com" 实则访问 "127.0.0.1" 这个本地换回地址,从而达到屏蔽网站的效果。

3. 记录常用IP地址

    通常情况下,通过在浏览器中输入常用网址来判断是否连上外网,但这种方法只能判断在DNS服务器地址有效的情况;本人经常使用 "ping 202.102.24.35"这条命令来判断本机是否连上外网("202.102.24.35"是一个外网地址),针对IP地址比较难记录,可以在hosts文件中添加"network 202.102.24.35":

  1. # Copyright (c) 1993-2009 Microsoft Corp.  
  2. #  
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.  
  4. #  
  5. # This file contains the mappings of IP addresses to host names. Each  
  6. # entry should be kept on an individual line. The IP address should  
  7. # be placed in the first column followed by the corresponding host name.  
  8. # The IP address and the host name should be separated by at least one  
  9. # space.  
  10. #  
  11. # Additionally, comments (such as these) may be inserted on individual  
  12. # lines or following the machine name denoted by a '#' symbol.  
  13. #  
  14. # For example:  
  15. #  
  16. #      102.54.94.97     rhino.acme.com          # source server  
  17. #       38.25.63.10     x.acme.com              # x client host  
  18.   
  19. # localhost name resolution is handled within DNS itself.  
  20. #   127.0.0.1       localhost  
  21. #   ::1             localhost  
  22. 202.102.24.35   network  
    以后就可以使用"ping network"来进行外网是否连通了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多