如何通过CMD编辑主机文件? [英] How to edit hosts file via CMD?
问题描述
您好,我想直接从命令提示符处阻止某些网站。
Hello I'd like to block some websites directly from the command prompt.
像这样回声:
0.0.0.0 websitename.com
我该怎么办这个? (操作系统:Windows 7)
How can I do this? (OS: Windows 7)
推荐答案
echo 0.0.0.0 websitename.com>> %WINDIR%\System32\Drivers\Etc\Hosts
>>
将 echo
的输出附加到文件中。
the >>
appends the output of echo
to the file.
请注意,这可能有两个原因不能像您想要的那样工作。您可能已经意识到了这些,但我还是提到了它们,以防万一。
Note that there are two reasons this might not work like you want it to. You may be aware of these, but I mention them just in case.
首先,它不会影响Web浏览器,例如,已经拥有最新的, 真实 IP地址已解析。因此,它并不总是立即生效。
First, it won't affect a web browser, for example, that already has the current, "real" IP address resolved. So, it won't always take effect right away.
第二,它要求您为域中的每个主机名添加一个条目;例如,仅添加 websitename.com
就会不阻止 www.websitename.com
。
Second, it requires you to add an entry for every host name on a domain; just adding websitename.com
will not block www.websitename.com
, for example.
这篇关于如何通过CMD编辑主机文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!