如果遇到网络或网站连接问题,则主机文件可能是问题的一部分。 本文介绍主机文件是什么、它的工作原理,以及为什么将其重置为默认状态可以解决常见的连接问题。
什么是 Hosts 文件
Hosts 文件是作系统用来将人友好主机名 ((例如 contoso.com) )映射到数字 Internet 协议 (IP) 地址的纯文本系统文件。 此映射允许系统在 IP 网络上标识和定位设备,并且是作系统 IP 实现的标准部分。
Hosts 文件中的每个条目都出现在自己的行上,并包括一个 IP 地址,后跟一个或多个主机名,用空格 (制表符或空格分隔) 。 以哈希字符 (#) 开头的行被视为注释,空行将被忽略。
如果从其默认状态修改了 Hosts 文件,则它可以替代正常的网络名称解析并导致连接问题。 将文件重置为其默认配置通常有助于解决访问网站或网络资源时出现的问题
重置主机文件
若要将主机文件重置回默认值,请根据你的操作系统执行以下步骤:
-
按 Windows 键,键入 记事本,然后选择 记事本应用图标。
-
复制以下文本,然后将文本粘贴到文件中:
# 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
-
在“ 文件 ”菜单上,选择“另存为”,并在“文件名”框中键入“主机” (,并在“ 文件名 ”框中键入引号) 。
-
将 “另存为类型 ”更改为 “所有文件” (*.*) 。 主机文件不能具有文件扩展名。
-
将文件保存到桌面并关闭记事本。
-
搜索 %WinDir%\System32\Drivers\Etc,然后选择“ 文件”文件夹 图标。注意:通常这是C:\Windows\System32\drivers\etc
-
右键单击现有“主机”文件,选择“ 重命名”,然后将文件名更改为“Hosts.old”。
-
将你从桌面创建的 Hosts 文件复制或移动到 %WinDir%\System32\Drivers\Etc 文件夹。 根据提示输入管理员密码,选择“继续”。
若要将主机文件重置回默认值,请执行以下步骤:
-
按 Windows 键,键入 记事本,然后选择 记事本系统图标。
-
复制以下文本,然后将文本粘贴到文件中:
# 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
-
在“ 文件 ”菜单上,选择“另存为”,并在“文件名”框中键入“主机” (,并在“ 文件名 ”框中键入引号) 。
-
将 “另存为类型 ”更改为 “所有文件” (*.*) 。 主机文件不能具有文件扩展名。
-
将文件保存到桌面并关闭记事本。
-
搜索 %WinDir%\System32\Drivers\Etc,然后选择“ 文件”文件夹 图标。注意:通常这是C:\Windows\System32\drivers\etc
-
右键单击现有“主机”文件,选择“ 重命名”,然后将文件名更改为“Hosts.old”。
-
将你从桌面创建的 Hosts 文件复制或移动到 %WinDir%\System32\Drivers\Etc 文件夹。 根据提示输入管理员密码,选择“继续”。