简单Hosts使用说明

1、查找hosts文件

首先,点击桌面的“我的电脑”,或者是通过开始菜单进入到我的电脑。

 

之后,进入到“C:WindowsSystem32driversetc”目录下,这个时候会看到目录下有一个“hosts”文件,这个就是所谓的hosts文件。

 

在xp以及03系统下对应的方法如上面所说。进入到“C:WindowsSystem32driversetc”目录下,即可找到对应的hosts文件。(默认位置为%SystemRoot%system32driversetc)

 

2、修改hosts文件

进入到该目录下之后,双击打开该文件。如下图,弹出“打开方式”窗口,选择以文本的形式打开。

 

之后,以文本的方式打开该文件。

原始的hosts文件内容如下:

# 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

 

同时,也可以通过下图的方式进行修改hosts文件(域名 + ip地址的方式)。

之后,进行保存,一般情况下是不能进行直接保存的,选择保存的位置。选择以没有后缀名的方式保存。

 

保存完成之后,拷贝对应保存好的hosts文件,拷贝到“C:WindowsSystem32driversetc”目录下(默认位置为%SystemRoot%system32driversetc)。

 

在点击替换的时候,有时候会提示权限的问题,点击“继续”进行替换。

 

最后,即可完成hosts文件的修改。

hosts文件在不同系统中所处的目录

Windows Vista/7/8/8.1: %windir%system32driversetc

Windows XP/Millennium:%windir%

Windows 95/98/Me:%WinDir%

Linux及其他类Unix操作系统:/etc

 

验证是否修改成功

在修改完成hosts文件之后,以(域名+ip地址的方式)修改完成之后,通过开始菜单,打开控制台,进行测试。(该域名为有效域名,测试才有效,否则该测试则不起作用)

  

之后,在控制台下输入“ping + 域名”,在域名是有效的情况下,会首先查找hosts文件中的信息,进行ping。则出现的信息ping的信息,同时显示的ip地址则就是hosts文件中你所配置的地址。

 

原文地址:https://www.cnblogs.com/xxsl/p/6124544.html