关于 Windows 10/11,
hosts 文件被隐藏、设置为只读,甚至无法在文件夹中找到,可以通过命令行直接定位、取消隐藏和只读属性。Windows 的 hosts 文件默认位置是:
C:\Windows\System32\drivers\etc\hosts
一、通过命令检查 hosts 文件
以管理员身份打开 CMD,执行:
cd /d C:\Windows\System32\drivers\etc
dir /a
/a 表示显示包括隐藏文件在内的所有文件。
如果能找到 hosts,执行:
attrib hosts
可能看到:
A R H C:\Windows\System32\drivers\etc\hosts
其中:
-
R:只读属性 -
H:隐藏属性 -
S:系统属性 -
A:存档属性
二、取消隐藏和只读属性
管理员 CMD 执行:
attrib -h -r -s C:\Windows\System32\drivers\etc\hosts
然后检查:
attrib C:\Windows\System32\drivers\etc\hosts
三、如果仍然找不到 hosts 文件
检查文件是否真的存在:
if exist C:\Windows\System32\drivers\etc\hosts (echo hosts exists) else (echo hosts not found)
如果不存在,可以创建:
notepad C:\Windows\System32\drivers\etc\hosts
记事本提示创建文件时,选择确定。
四、修改 hosts 文件
推荐使用管理员权限打开记事本:
-
开始菜单搜索「记事本」。
-
右键选择「以管理员身份运行」。
-
点击文件 → 打开。
-
输入:
C:\Windows\System32\drivers\etc\hosts
-
文件类型选择「所有文件 (.)」。
-
打开并编辑。
五、如果 hosts 被自动设置为隐藏或只读
可以检查文件权限:
icacls C:\Windows\System32\drivers\etc\hosts
还可以检查文件是否被其他软件或安全策略修改。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
