hosts文件配置

    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
    以后就可以使用"ping network"来进行外网是否连通了。

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值