您的位置:首页 > 其它

[乐意黎原创]hosts文件位置及说明

2018-03-02 10:07 375 查看
What is a "hosts" file?
Before we get too far, we need to make sure we are all on the same page. What is a "hosts" file? A "hosts" file in Windows 7, or other versions of the Windows operating system, like Windows 2000, XP, and Vista, is simply a text file containing IP (Internet Protocol) address to host name mappings. Your computer checks this file first to resolve any network names to its corresponding IP address before it tries to check the Internet.To get a better understanding of it and its relation to computer security, we'll cover the following areas:hosts file location and content
how to use it
typical malicious use

Hosts file location and content

The "hosts" file is typically located at c:\windows\system32\drivers\etc. The file name is "hosts". Notice that it has no file extension.In Windows 7, the location hasn't changed. The file contains some comments (lines preceded by the "#" character) explaining what the file is and how entries should be formatted, and a couple of mappings for the localhost as follows:127.0.0.1 localhost
::1 localhost
The IP address 127.0.0.1 is the IP version 4 address for the name "localhost".The IP address ::1 is the IP version 6 address for the same name--"localhost".

How to use the "hosts" file

Most computer users don't have to deal with the "hosts" file, but if you have a lot of computers in your home network, and you set them up to use particular IP addresses, then using their IP addresses to access them can get tiring. Through the hosts file, you can assign names to the IP addresses of your computers.By editing the "hosts" file, you can simply add one line per IP address-name mapping--making sure the first character of the IP address starts at the very first position of the line and the IP address is followed by at least one space before the hostname specification. Comments can be added to each mapping by following the hostname specification with at least one space, the "#" character, and the comment. For example: 192.168.0.10 mywebserver #this is my webserver.
 
 hosts文件是一个用于储存计算机网络中各节点信息的计算机文件。这个文件负责将主机域名映射到相应的IP地址。hosts文件通常用于补充或取代网络中DNS的功能。和DNS不同的是,计算机的用户可以直接对hosts文件进行控制。hosts文件的作用非常大,可以自由解析域名。

hosts文件在不同操作系统中的位置如下表所示:
Windows:%SystemRoot%\System32\drivers\etc\hosts
典型的XP系统hosts文件位置:C:\windows\system32\drivers\etc
Windows 95/98/Me:%WinDir%\

Android:/etc/hosts(指向/system/etc/hosts的符号链接)
iOS:/etc/hosts(指向/private/etc/hosts的符号链接)
Mac OS X 10.0–10.1.5:通过NetInfo或niload设置
Mac OS X 10.2和更新版本:/etc/hosts(指向/private/etc/hosts的符号链接)
Unix、类Unix系统(例如Linux等):/etc/hosts
Windows Mobile、Windows Phone:注册表项HKEY_LOCAL_MACHINE\Comm\Tcpip\Hosts
Symbian OS 6.1–9.0:C:\system\data\hosts
Symbian OS 9.1+:C:\private\10000882\hosts

hosts文件的一些用途
1,将广告域名重定向到本地IP地址:127.0.0.1上来过滤广告。
2,hosts文件可用于拦截一些恶意网站的请求,从而防止访问欺诈网站或感染一些病毒或恶意软件。
3,使用hosts文件来强制将网站指定到正确的IP上。

另外,修改hosts文件的技巧
自己建个文件重命名为.cmd扩展名
复制以下内容进去保存一下,要改hosts的时候运行一下就出来了
@echo 去除hosts文件的只读和隐藏属性,防止hosts文件无法修改
attrib -r -h %Systemroot%\System32\Drivers\Etc\hosts
@echo 用记事本打开hosts文件
notepad.exe %Systemroot%\System32\Drivers\Etc\hosts其实后面可以开始-运行 输入回车:
notepad.exe %Systemroot%\System32\Drivers\Etc\hosts

也可以在桌面为hosts新建个快捷方式,需要用的时候就直接用记事本打开。

-------------------------------------------------------------------------------------------------
乐意黎
2018-03-01
本文地址: http://blog.csdn.net/aerchi/article/details/79420010
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: