如何在Windows 8的主机文件中阻止网站

image

Windows 8 takes a new approach to the hosts file by default – it won’t allow you to block Facebook and other websites by modifying your hosts file. Luckily, there’s a way to bypass this restriction.

Windows 8默认情况下对主机文件采取了一种新方法–不允许您通过修改主机文件来阻止Facebook和其他网站。 幸运的是,有一种方法可以绕过此限制。

When you add certain website addresses to Windows 8’s hosts file, Windows 8 will automatically remove them, effectively ignoring your changes. Microsoft isn’t just doing this to annoy us – there’s a good reason for it.

当您将某些网站地址添加到Windows 8的主机文件中时,Windows 8将自动删除它们,从而有效地忽略了您的更改。 微软不只是为了惹恼我们,还有一个很好的理由。

什么是主机文件? (What’s a Hosts File?)

When you access a website, your computer contacts your domain name system (DNS) server and requests its numerical IP address. For example, Facebook.com maps to 66.220.158.70. Your computer will then connect to this numerical IP address and access the website.

当您访问网站时,您的计算机将与您的域名系统(DNS)服务器联系并请求其数字IP地址。 例如,Facebook.com映射到66.220.158.70。 然后,您的计算机将连接到该数字IP地址并访问该网站。

Your hosts file is a file, local to your computer, that can override this behavior. By editing your hosts file, you can point Facebook.com at any IP address you want. Some people use this trick to block websites – for example, you could point Facebook.com at 127.0.0.1, which is your computer’s local IP address. When someone tries to access Facebook.com on your computer, your computer will attempt to connect to itself at 127.0.0.1. It won’t find a web server, so the connection will immediately fail.

您的主机文件是计算机本地的文件,可以覆盖此行为。 通过编辑主机文件,您可以将Facebook.com指向所需的任何IP地址。 某些人使用此技巧来阻止网站-例如,您可以将Facebook.com指向127.0.0.1,这是您计算机的本地IP地址。 当有人尝试在您的计算机上访问Facebook.com时,您的计算机将尝试以127.0.0.1与其自身连接。 它找不到Web服务器,因此连接将立即失败。

为什么要实行限制 (Why the Restriction is in Place)

Unfortunately, malware often edits the hosts file to add such lines. For example, the malware could point Facebook.com at a different IP address entirely – one run by a malicious organization. The malicious website could even be disguised as Facebook.com. A user would look at their address bar, see Facebook.com, and never consider that they may be looking at a phishing site.

不幸的是,恶意软件经常编辑主机文件以添加此类行。 例如,该恶意软件可能将Facebook.com完全指向一个不同的IP地址-一个由恶意组织运行的IP地址。 该恶意网站甚至可能伪装成Facebook.com。 用户会看着他们的地址栏,访问Facebook.com,却从不认为他们正在寻找钓鱼网站。

To prevent this from taking place, Windows 8 (more specifically, the Windows Defender antivirus included with Windows 8) monitors your hosts file. When it notices that a website such as Facebook.com has been added to your hosts file, it immediately removes the entry and allows connections to the normal Facebook.com website.

为了防止这种情况的发生,Windows 8(更具体地说,Windows 8随附的Windows Defender防病毒软件)会监视您的主机文件。 当它发现某个网站(例如Facebook.com)已添加到您的主机文件中时,它会立即删除该条目并允许连接到正常的Facebook.com网站。

This is actually an important security feature for many users that would never consider editing their hosts file. However, if you’re a tech savvy user that wants to edit your hosts file to block a website, you can disable this restriction.

对于许多从不考虑编辑其主机文件的用户,这实际上是一项重要的安全功能。 但是,如果您是精通技术的用户,想要编辑主机文件以阻止网站,则可以禁用此限制。

绕过限制的方法 (Ways to Bypass the Restriction)

Because this restriction is put in place by the Windows Defender (formerly known as Microsoft Security Essentials) antivirus included with Windows 8, you have several options for bypassing it:

由于Windows 8随附的Windows Defender(以前称为Microsoft Security Essentials)防病毒软件已设置了此限制,因此有几种方法可以绕过它:

  • Exclude the hosts file from being monitored in Windows Defender – If you want to use Windows Defender instead of a third-party antivirus, this is your best option. This does mean that Windows won’t protect you from malicious hosts file entries added by malware, however.

    从Windows Defender中排除对主机文件的监视 –如果要使用Windows Defender而不是第三方防病毒软件,这是最佳选择。 但是,这确实意味着Windows不会保护您免受恶意主机添加的恶意主机文件条目的侵害。

  • Install a Third-Party Antivirus – Many third-party antivirus applications won’t be as aggressive about policing your hosts file. Many, such as avast! and AVG, are free. When you install a third-party antivirus, Windows Defender will disable itself.

    安装第三方防病毒软件 –许多第三方防病毒应用程序在管理主机文件方面并不那么积极。 很多,例如avast!AVG是免费的。 当您安装第三方防病毒程序时,Windows Defender将禁用自身。

You can also disable Windows Defender entirely, but that isn’t a good idea unless you’re using a third-party antivirus. Even if you’re a careful computer user, having multiple layers of protection is a good security practice.

您还可以完全禁用Windows Defender,但这不是一个好主意,除非您使用的是第三方防病毒软件。 即使您是认真的计算机用户,拥有多层保护也是一种很好的安全习惯。

排除主机文件 (Excluding the Hosts File)

To exclude the hosts file from being monitored in Windows Defender, first open Windows Defender – press the Windows key, type Windows Defender, and press Enter.

要从Windows Defender中排除要监视的主机文件,请首先打开Windows Defender –按Windows键,键入Windows Defender,然后按Enter。

image

Click the Settings tab and select the Excluded files and locations category.

单击设置选项卡,然后选择排除的文件和位置类别。

image

Click the Browse button and navigate to the following file:

单击浏览按钮,然后导航到以下文件:

C:\Windows\System32\Drivers\etc\hosts

C:\ Windows \ System32 \ Drivers \ etc \ hosts

(If you installed Windows to a different directory, start in that directory instead of C:\Windows)

(如果将Windows安装到其他目​​录,请从该目录而不是C:\ Windows开始)

image

Click the Add button and then click Save Changes to save your changes.

单击添加按钮,然后单击保存更改以保存更改。

image

You may now edit the hosts file normally.

现在,您可以正常编辑主机文件。

编辑主机文件 (Editing Your Hosts File)

You’ll have to edit your hosts file as administrator. If you open it normally and try to save it, you’ll see a message stating you don’t have permission to save a file in its location.

您必须以管理员身份编辑主机文件。 如果您正常打开它并尝试保存它,将会看到一条消息,指出您无权将文件保存在其位置。

image

To launch Notepad as administrator, press the Windows key, type Notepad, right-click the Notepad application that appears, and select Run as administrator. (You can also launch any other text editor you prefer, such as Notepad++.)

要以管理员身份启动记事本,请按Windows键,键入记事本,右键单击出现的记事本应用程序,然后选择以管理员身份运行 。 (您还可以启动您喜欢的任何其他文本编辑器,例如Notepad ++。)

image

Click File –> Open in the Notepad window and navigate to the following file:

在记事本窗口中单击文件–>打开,然后导航到以下文件:

C:\Windows\System32\Drivers\etc\hosts

C:\ Windows \ System32 \ Drivers \ etc \ hosts

You’ll have to select All Files in the file type box at the bottom of the open dialog or the hosts file won’t appear in the list.

您必须在打开的对话框底部的文件类型框中选择所有文件,否则主机文件将不会出现在列表中。

image

Add a line for each website you want to block. Type the number 127.0.0.1, followed by a space or tab, and then type the name of a website. For example, the following lines would block both facebook.com and example.com:

为您要阻止的每个网站添加一行。 键入数字127.0.0.1,后跟空格或制表符,然后键入网站的名称。 例如,以下几行会同时阻止facebook.com和example.com:

127.0.0.1 facebook.com

127.0.0.1 facebook.com

127.0.0.1 example.com

127.0.0.1 example.com

image

Save the file after you’re done. Your changes will take effect immediately and the website will be blocked – no system or browser restart required.

完成后保存文件。 您所做的更改将立即生效,并且网站将被阻止-无需重新启动系统或浏览器。

image

翻译自: https://www.howtogeek.com/122404/how-to-block-websites-in-windows-8s-hosts-file/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值