Hosts file in Windows 11/10的Hosts 文件用于将主机名映射到 IP 地址。此 Hosts 文件位于Windows文件夹的深处。它是一个纯文本文件,原始默认 Hosts 文件的大小约为 824 字节。
Windows 11/10 中的主机文件
在这篇文章中,我们将看到它的位置以及如何在Windows 11/10中管理、锁定或编辑 Hosts 文件。我们将讨论以下内容:
- 主机文件位置
- 锁定 Hosts(Lock Hosts)文件以防止劫持
- 使用 Hosts 文件阻止网站
- 如何编辑主机文件
- 使用免费的 Hosts文件编辑器(File Editor)软件。
让我们来看看它们。
主机文件位置
Windows中的 Hosts 文件位于以下位置:
C:\Windows\System32\drivers\etc
锁定 Hosts(Lock Hosts)文件以防止劫持
想象一下点击www.thewindowsclub.com并在您的浏览器中看到一个完全不同的网站加载。恶意软件(Malware)可以通过更改您的 Hosts 文件来重定向您计算机上的Web地址。这称为主机文件劫持(Host File Hijack)。
为了防止主机(Host)文件劫持,您可以导航到它,右键单击它,选择属性(Properties)并将其设为只读(Read-only)文件。这将锁定您的 Hosts 文件并防止任何人或任何恶意软件对其进行写入。
使用 Hosts 文件阻止网站
要使用Hosts File(Hosts File)阻止网站,只需添加以下条目:
127.0.0.1 blocksite.com
虽然我不这样做,但许多用户喜欢手动添加条目以阻止打开一个或多个特定网站。其他人则喜欢从mvps.org(mvps.org)等知名来源下载和使用 List ,以添加阻止恶意软件站点打开的条目。
如何在Windows 11/10
在Windows 11/10中编辑 Hosts 文件:
- 打开资源管理器
- 导航(Navigate)到 System32driversetc 位置
- 找到主机文件
- 右键单击它并选择记事本(Notepad)
- 进行更改并保存。
现在让我们进行详细的解释。
要编辑Hosts文件,请导航到以下文件夹位置:
C:\Windows\System32\drivers\etc\
在这里,您将看到 Hosts 文件。右键单击它并选择记事本(Notepad)。进行更改并保存(Save)。
但有时,即使您使用管理凭据登录,您也可能会收到以下错误消息:
Access to C:\Windows\System32\drivers\etc\ hosts was denied
或者
Cannot create the C:\Windows\System32\drivers\etc\hosts file. Make sure that the path and file name are correct.
在这种情况下,请在开始(Start)搜索中键入记事本(Notepad),然后右键单击记事本(Notepad)结果。选择以管理员身份运行(Run as administrator)。
打开Hosts文件,进行必要的更改,然后单击Save。
使用免费的 Hosts文件编辑器(File Editor)软件
如果您正在寻找更简单的方法,您可以使用免费的 Hosts 文件编辑器(Editor)软件。
1]使用HostsMan
虽然您始终可以手动手动管理或编辑 Hosts 文件,但我建议您使用HostsMan等第三方免费软件工具来执行此操作。
HostsMan是一个功能丰富的工具,可让您在 Hosts 文件中添加、删除、编辑条目。它还可以让您轻松添加有助于阻止恶意软件站点的第三方主机列表,并让您轻松启用或禁用主机文件。它包括一个内置的主机文件更新器和一个主机编辑器。它可以让您扫描主机文件以查找错误、重复和可能的劫持 - 还可以让您创建排除(Exclusion)列表。它提供的一项更有用的功能是 Hosts 文件备份管理器。将您的 Hosts 文件备份(Backup)到一个安全的地方,并在需要时使用它来恢复它。
Hostman还允许您刷新 DNS(Flush DNS)缓存、使用文本编辑器打开主机、计算主机数量、查找重复项、替换 IP、扫描主机以查找恶意条目、重新排列主机、管理DNS 客户端服务(DNS Client Service)等等。简而言之,它是您甚至需要的唯一主机管理器。(Manager)您可以从它的主页(home page)下载它。
2]使用SysMate主机文件管理器
SysMate 托管文件管理器(SysMate Hosts File Manager),是另一个让您这样做的工具。使用Host File Walker,您可以将尽可能多的记录添加到系统 hosts 文件中。它甚至可以让您备份和恢复主机文件(File)。
3]使用主机文件编辑器工具
主机文件编辑器(Host File Editor)是您可以使用的另一个好工具。它具有以下特点:
- 从系统托盘启用和禁用主机文件
- 剪切(Cut)、复制、粘贴、复制、启用、禁用和移动条目
- 过滤和排序主机条目
- (Backup)环境切换时备份和恢复各种hosts文件配置
- Ping 端点以检查可用性。
你可以从这里(from here)下载。它也提供便携式版本。
提示(TIP):如何在Windows中手动(Windows)将 Hosts 文件重置(reset Hosts file)为默认值,您可能也会感兴趣。
如果您的浏览器被劫持,您可能会发现这篇关于浏览器劫持和免费浏览器劫持删除工具(Browser Hijacking and Free Browser Hijacker Removal Tools)的帖子很有帮助。(If your browser has been hijacked, you might find this post on Browser Hijacking and Free Browser Hijacker Removal Tools helpful.)
Hosts File in Windows 11/10: Location, Edit, Lock, Manage
The Hosts file in Windows 11/10, is used to map hostnames to IP addresses. This Hosts file is located deep down in the Windows folder. It is a plain text file, and the size of the original default Hosts file is around 824 bytes.
Hosts File in Windows 11/10
In this post, we will see its location and also how to manage, lock, or edit the Hosts file in Windows 11/10. We will discuss the following:
- Host file location
- Lock Hosts file to prevent hijacking
- Block website using the Hosts file
- How to edit the Hosts file
- Using free Hosts File Editor software.
Let us take a look at them.
Host file location
The Hosts file in Windows is located at the following location:
C:\Windows\System32\drivers\etc
Lock Hosts file to prevent hijacking
Imagine clicking on www.thewindowsclub.com and seeing a completely different website load in your browser. Malware can redirect Web addresses on your computer by altering your Hosts file. This is referred to as the Host File Hijack.
To prevent Host file hijacks, you may navigate to it, right-click on it, select Properties and make it a Read-only file. This will lock down your Hosts file and prevent anyone or any malware from writing to it.
Block website using the Hosts file
To block a website using the Hosts File, simply add the following entry:
127.0.0.1 blocksite.com
Although I do not do it, many users like to manually add entries to it in order to block the opening of one or more particular websites. Others, like to download and use List from well-known sources like mvps.org, to add entries that block malware sites from opening.
How to edit Hosts file in Windows 11/10
To edit the Hosts file in Windows 11/10:
- Open Explorer
- Navigate to \System32\drivers\etc\ location
- Locate Hosts file
- Right-click on it and select Notepad
- Make the changes and Save.
Now let us go into a detailed explanation.
To edit the Hosts file, navigate to the following folder location:
C:\Windows\System32\drivers\etc\
Here you will see the Hosts file. Right-click on it and select Notepad. Make the changes and Save.
But sometimes, even when you are logged on with administrative credentials, you may receive the following error message:
Access to C:\Windows\System32\drivers\etc\ hosts was denied
Or
Cannot create the C:\Windows\System32\drivers\etc\hosts file. Make sure that the path and file name are correct.
In this case, type Notepad in Start search and right-click on the Notepad result. Select Run as administrator.
Open the Hosts file, make the necessary changes, and then click Save.
Using free Hosts File Editor software
If you are looking for an easier way, you can use a free Hosts file Editor software.
1] Using HostsMan
While you can always manually manage or edit Hosts file manually, I would like to suggest that you use a third-party freeware tool like HostsMan to do it.
HostsMan is a feature-rich tool that lets you add, remove, edit entries in the Hosts file. It also lets you easily add third-party Hosts lists that help in blocking malware sites and lets you easily enable or disable the Hosts file. It includes a built-in hosts file updater & a hosts editor. It lets you scan the hosts file for errors, duplicates, and possible hijacks – and also lets you create an Exclusion list. One more useful feature it offers is the Hosts file backup manager. Backup your Hosts file to a safe place and use it to restore it, should the need arise.
Hostman also lets you Flush DNS cache, open Hosts with a text editor, count the number of hosts, find duplicates, replace IP, scan hosts for malicious entries, rearrange hosts, manage DNS Client Service and more. In short, it’s the only Hosts Manager that you will even need. You can download it from its home page.
2] Using SysMate Hosts File Manager
SysMate Hosts File Manager and is another tool that lets you do so. With Host File Walker you can add as many records to the system hosts file. It even lets you backup and restore the Hosts File.
3] Using Host File Editor tool
Host File Editor is another good tool that you can use. It has the following features:
- Enable and disable hosts file from the system tray
- Cut, copy, paste, duplicate, enable, disable and move entries
- Filter and sort host entries
- Backup and restore various hosts file configurations when switching between environments
- Ping endpoints to check availability.
You can download it from here. It offers a portable version too.
TIP: How to manually reset Hosts file back to default in Windows may also interest you.
If your browser has been hijacked, you might find this post on Browser Hijacking and Free Browser Hijacker Removal Tools helpful.