hosts文件原理及作用

来源:互联网 发布:1024程序员节 微博 编辑:程序博客网 时间:2024/06/05 11:31
在Android里的目录/system/etc/下有一个hosts文件,这个hosts文件时做什么用的?

作用:
      在访问某个网站时,我们一般是根据域名访问,比如本站的域名是:http://www.tsnrose.com.我们在浏览器中输入以上域名后,后台就会通过相关协议经由DNS服务器把该域名解析成对应的IP地址:65.49.77.192。获取了这个IP地址后我们的计算机才能与站点交互,比如请求页面,留言评论等。(这是由http协议本身特性决定的:http协议工作在tcp/ip协议上,而tcp/ip协议的核心就是IP)。hosts文件起作用的地方就是在由域名转换成IP的过程中。hosts文件在本地保存了一个域名和IP地址的映射,根据Windows系统规定,在进行DNS请求以前,Windows系统会先检查自己的Hosts文件中是否有这个地址映射关系,如果有则调用这个IP地址映射,如果没有再向已知的DNS服务器提出域名解析。也就是说Hosts的请求级别比DNS高。


       window7的hosts文件地址为:C:\Windows\System32\drivers\etc\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             localhost



      

      hosts文件应该可以有效解决在国内的android系统上无法登陆youtube等问题,但是如何查询到www.youtube.com等的有效的ip地址呢?

     应该通过站长工具就可以查询到:http://tool.chinaz.com/Ip/?ip=ethioyoutube.com

       这样的网站有很多,但是现在我还没有测试,我将明天android上测试,看具体效果。


  参考文章:http://blog.renren.com/share/341043217/7558561852

             http://kbs.cnki.net/forums/5715/ShowThread.aspx
    

        



原创粉丝点击