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"来进行外网是否连通了。

hosts文件配置及主要作用的更多相关文章

  1. hosts文件配置作用

    hosts文件默认路径: C:\Windows\System32\drivers\etc hosts文件认识 Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域 ...

  2. hosts文件配置参数介绍

    hosts文件配置参数介绍 1, ansible_ssh_host : 指定主机别名对应的真实 IP,如:100 ansible_ssh_host=192.168.1.100,随后连接该主机无须指定完 ...

  3. Oracle LISTENER 主机名修改为IP地址后LISTENER无法监听到实例 oracle监听错误与hosts文件配置

    为什么listener.ora文件里面HOST后面到底应该输入IP地址还是主机名.我的经验告诉我,这边最好使用主机名.很多的时候,一个机器绑定的不只一个IP地址,如HOST后面是IP地址,那么ORAC ...

  4. Linux操作系统下/etc/hosts文件配置方法

    1.关于/etc/host,主机名和IP配置文件 Hosts - The static table lookup for host name(主机名查询静态表) hosts文件是Linux系统中一个负 ...

  5. hosts 文件的位置及作用

    一.位置 1.Window系统位置 C:\Windows\System32\drivers\etc 2.Linux系统位置 /etc/hosts 二.作用 综述:Hosts文件中指定了域名和IP地址的 ...

  6. Mac下hosts文件配置

    工作中总会因为莫名其妙的原因,比如Mac下面打不开某网站,但是在windows 7下面却可以,此时只需两步即可完成在Mac下面上网.在Windows下面Win+R,输入cmd,进入命令行,将在wind ...

  7. hosts文件配置不生效的解决办法

    分析可能的原因并给出相应的解决方案. 第一 种情况,在开启浏览器的时候修改磁盘上的hosts文件,比如说加了原先没有的一句"127.0.0.1 www.360.cn",保存host ...

  8. 操作系统/etc/hosts文件配置

    windows对应 C:\Windows\system32\drivers\etc\hosts linux: /etc/hosts Hosts - The static table lookup fo ...

  9. 修改C:\WINDOWS\system32\drivers\etc\hosts 文件有什么作用

    host是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联"数据库",当用户在浏览器中输入一个需要登录的网址时,系统会 ...

随机推荐

  1. Word Search——经典题(还没细看)

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  2. python调用.so

    python调用动态链接库的基本过程 动态链接库在Windows中为.dll文件,在linux中为.so文件.以linux平台为例说明python调用.so文件的使用方法. 本例中默认读者已经掌握动态 ...

  3. WordPress函数query_posts用法汇总

    最近经常有网友跟我咨询WordPress函数query_posts的相关用法,说起来query_posts实在是太强大,参数无数,用法更是无数,如果让我说它的用法,我根本没法一一说清楚.开始之前,你可 ...

  4. C++中正确使用PRId64

    http://blog.csdn.net/win_lin/article/details/7912693

  5. 错误:Eclipse老是出现 updating error reports database

    Eclipse 火星版(Mars)一直出现 updating error reports database. Window--->Preferences--->General---> ...

  6. Codeforces 1131 F. Asya And Kittens-双向链表(模拟或者STL list)+并查集(或者STL list的splice()函数)-对不起,我太菜了。。。 (Codeforces Round #541 (Div. 2))

    F. Asya And Kittens time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces 1082 C. Multi-Subject Competition-有点意思 (Educational Codeforces Round 55 (Rated for Div. 2))

    C. Multi-Subject Competition time limit per test 2 seconds memory limit per test 256 megabytes input ...

  8. 主元素 II

    主元素 II 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的三分之一. 样例 给出数组[1,2,1,2,1,3,3] 返回 1 注意 数组中只有唯一的主元素 挑战 要求时间复 ...

  9. 【模拟退火】Petrozavodsk Winter Training Camp 2017 Day 1: Jagiellonian U Contest, Monday, January 30, 2017 Problem F. Factory

    让你在平面上取一个点,使得其到给定的所有点的距离和最小. 就是“费马点”. 模拟退火……日后学习一下,这是从网上扒的,先存下. #include<iostream> #include< ...

  10. 20162327实验一Java开发环境的熟悉实验报告

    20162327 <程序设计与数据结构>第一次实验报告 基础知识 1.JDB的使用 使用JDB调试程序需要以下五个步骤: 1.设置断点 stop in 2.run 3.print 4.ne ...