Hosts文件丢失/异常,如何还原默认

来自电脑维修知识库
Wikiadmin讨论 | 贡献2024年12月23日 (一) 20:55的版本

跳转至: 导航搜索

知识库编号:0982


问题现象

部分情况下,hosts文件出现异常、丢失等情况。

可以参考以下方法进行还原出厂默认hosts。


解决方案

为了以防万一,可以提前备份hosts文件C:\Windows\System32\drivers\etc

Hosts文件1.png

CMD管理员身份运行如下命令:(提示覆盖输入yes)输入完成之后需要等待一段时间


for /f %P in ('dir %windir%\\WinSxS\\hosts /b /s') do copy %P %windir%\\System32\\drivers\\etc & echo %P & Notepad %P


Hosts文件2.png


也可以直接复制粘贴如下文本到hosts文件


  1. Copyright (c) 1993-2009 Microsoft Corp.
  2. This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  3. This file contains the mappings of IP addresses to host names. Each
  4. entry should be kept on an individual line. The IP address should
  5. be placed in the first column followed by the corresponding host name.
  6. The IP address and the host name should be separated by at least one
  7. space.
  8. Additionally, comments (such as these) may be inserted on individual
  9. lines or following the machine name denoted by a '#' symbol.
  10. For example:
  11. 102.54.94.97 rhino.acme.com # source server
  12. 38.25.63.10 x.acme.com # x client host
  1. localhost name resolution is handled within DNS itself.
  2. 127.0.0.1 localhost
  3. ::1 localhost