host文件配置 了解

https://blog.csdn.net/CJF_iceKing/article/details/7702694

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

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

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

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

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

2. 屏蔽网站

    在hosts文件中添加

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":

# 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
202.102.24.35	network

  

注意:要以管理员权限打开记事本,然后在记事本中打开host进行修改。

注销时,以同样的方式打开,在修改的前面加上#  然后关闭即可。

 

posted @ 2018-08-03 16:45  静悟生慧  阅读(5946)  评论(0编辑  收藏  举报