文件位置
类似 Linux 下的 /etc/hosts
文件 win 的文件位置位于
C:\Windows\System32\drivers\etc\
修改 hosts 文件
方法一 修改 hosts 文件权限
- 定位 hosts 文件目录, 资源管理器地址栏输入
- 修改文件属性后在资源管理器地址栏输入以下命令并回车, 使用记事本打开 hosts 文件
notepad.exe C:\Windows\System32\drivers\etc\hosts
方法二 使用批处理命令,提升管理员权限打开 hosts 文件
将以下代码保存为edit_host.bat
或其他以.bat
为后缀的文件, 双击运行edit_host.bat
@echo off&color 17
if exist "%SystemRoot%\SysWOW64" path %path%;%windir%\SysNative;%SystemRoot%\SysWOW64;%~dp0
bcdedit >nul
if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
:UACPrompt
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit
exit /B
:UACAdmin
cd /d "%~dp0"
C:\Windows\System32\notepad.exe C:\Windows\System32\drivers\etc\hosts
exit
其他方法
https://jingyan.baidu.com/article/c45ad29cd98d4c051753e282.html