JCHub

  • Home
  • Category
    • A/V
    • WebRTC
    • Beauty of Programming
    • Linux
    • Windows
    • Moments of Life
    • Campus Life
  • Reference
    • API Reference
    • Utilities
    • AV Test
    • Doc
  • Message Board
  • About
JCHub
Code as My Sword, Lost in Obsession
  1. Main page
  2. Beauty of Programming
  3. Main content

hosts文件

2013年11月14日 1435hotness 0likes 0comments

Hosts是一个没有扩展名的系统文件,可以用记事本等文本编辑工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联“数据库”,当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从Hosts文件中寻找对应的IP地址,一旦找到,系统会立即打开对应网页,如果没有找到,则系统再会将网址提交DNS域名解析服务器进行IP地址的解析。

在Internet的前身ARPANET中并没有对网络中各节点的地址使用DNS进行解析。由于当时对于这个用途并没有中心化的系统,每个网络节点都使用自有的网络节点地图,并指派相应的名称方便用户记忆,当时并没有任何系统来保证网络中的所有系统都用同样的名称表示,也没有方法来读取其他用户的hosts文件并自动复制。

ARPANET的规模较小,这样就也就允许了在很多情况使用hosts文件来命名一些事先约定的名称。其中典型的网络节点都有一个地址,并可能有多个名称。但是当个人网络不断庞大之后,对hosts文件进行管理的难度也越来越大。

hosts文件在不同操作系统(甚至不同Windows版本)的位置都不大一样:
Windows NT/2000/XP/Vista/7/8(即微软NT系列操作系统):默认位置为%SystemRoot%\system32\drivers\etc\,但也可以改变。动态目录由注册表键\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\DataBasePath决定。例如,Windows XP/Windows 7/Windows 8 安装在C:\WINDOWS,那么Hosts文件就在C:\WINDOWS\system32\drivers\etc中。
Linux及其他类Unix操作系统:/etc
Mac OS 9及更早的系统:System Folder: Preferences或System folder(文件格式可能与Windows和Linux所对应的文件不同)
Mac OS X:/private/etc(使用BSD风格的hosts文件)
Android:/system/etc/hosts
iOS(iPhone):/etc
iOS(iPad):/private/etc

hosts文件也可以用于其它情况,例如可以将已知的广告服务器重定向到无广告的机器(通常是本地的IP地址:127.0.0.1)上来过滤广告。同时也可以通过不下载网络广告,从而减少带宽。使用hosts文件还可以减少对DNS服务器的访问来加快访问速度并减少带宽消耗。
hosts文件的另一个重要用途就是用于拦截一些恶意网站的请求,从而防止访问欺诈网站或感染一些病毒或恶意软件。但同时,这个文件也可能被病毒或恶意软件所利用来阻止用户更新杀毒软件或访问特定网站。
也可以通过修改hosts文件来强制将特定网站指定到正确的IP上,访问一些特殊网站。

hosts文件默认内容如下:
# copyright (c) 1993-1999 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
127.0.0.1 localhost

This article is licensed with Creative Commons Attribution-NonCommercial-No Derivatives 4.0 International License
Tag: Nothing
Last updated:2013年11月14日

Jeff

管理员——代码为剑,如痴如醉

Tip the author Like
< Last article
Next article >

Comments

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
Cancel

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts
  • Nodejs C++ addon开发简介
  • Google ProtoBuf协议介绍
  • Intel Media SDK 内存优化(转)
  • 网络字节转换到本地字节的函数模板
  • 解决Ubuntu下vlc无法播放文件
Categories

COPYRIGHT © 2026 jianchihu.net. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang