什么是 Windows 10 中的主机文件?(What is a hosts file in Windows 10?)
'hosts' 文件是一个纯文本文件,它将(text file)主机名(hostnames)映射到 IP 地址。主机文件(host file)有助于寻址计算机网络(computer network)中的网络节点。主机名是分配给网络上的设备(主机)的人性化名称或标签(name or label),用于区分特定网络或互联网上的一个设备与另一个设备。
如果您是精通技术的人,您将能够访问和修改Windows主机文件以解决某些问题或阻止您设备上的任何网站。hosts 文件位于计算机上的C:\Windows\system32\drivers\etc\hosts 。(on your computer. )由于它是纯文本文件(text file),因此可以在记事本中打开和编辑。但有时您在打开 hosts 文件时可能会遇到“拒绝访问(Access Denied)”错误。您将如何编辑主机文件(host file)?此错误不会让您打开或编辑计算机上的主机文件。在本文中,我们将讨论解决Windows 10(Windows 10)上无法编辑主机文件问题的各种方法。
编辑主机文件是可能的,您可能出于各种原因需要这样做。
- 您可以通过在将网站IP 地址(IP address)映射到您自己选择的主机名的主机文件中添加所需条目来创建网站快捷方式。
- 您可以通过将其主机名映射到您自己计算机的IP 地址(IP address)127.0.0.1(也称为环回IP 地址(IP address))来阻止任何网站或广告(website or ads)。
修复在(Fix Access)Windows 10中编辑主机文件时拒绝访问
确保(Make)创建一个还原点(restore point) 以防万一(case something)出现问题。
为什么我不能以管理员身份编辑主机文件?(Why can’t I edit the hosts file, even as Administrator?)
即使您尝试以管理员(Administrator)身份打开文件或使用内置管理员帐户(Administrator account)修改或编辑 hosts 文件,您仍然无法对文件本身进行任何更改。原因是对主机文件进行任何更改所需的访问或权限由(access or permission)TrustedInstaller 或 SYSTEM(TrustedInstaller or SYSTEM)控制。
方法 1 – 以管理员权限打开记事本(Method 1 – Open Notepad with Administrator Access)
大多数人使用记事本作为Windows 10上的文本编辑器(text editor)。因此,在编辑主机文件(host file)之前,您需要在设备上以管理员身份运行(Administrator)记事本(Notepad)。
1. 按Windows Key + S调出Windows 搜索框(Windows Search box)。
2.输入记事本(notepad),在搜索结果中,您将看到记事本的快捷方式。(shortcut for Notepad.)
3. 右键单击记事本(Notepad)并从上下文菜单中选择“以管理员身份运行”。(Run as administrator)
4. 将出现提示。选择是(Yes)继续。
5.将出现记事本窗口。(Notepad window) 从菜单(Menu)中选择文件(File)选项,然后单击“打开(Open)”。
6. 要打开 hosts 文件,请浏览至C:\Windows\system32\drivers\etc.
7. 如果您在此文件夹中看不到 hosts 文件,请在下面的选项中选择“所有文件(All Files)”。
8. 选择主机文件(hosts file),然后单击打开。(Open.)
9. 您现在可以看到 hosts 文件的内容。
10. 在 hosts 文件中修改或进行所需的更改。
11. 从记事本菜单转到 File > Save或按Ctrl+S to save the changes.
需要注意的是,此方法适用于所有文本编辑器程序(text editor program)。因此,如果您使用除记事本之外的其他文本编辑器程序(text editor program),您只需要以管理员权限打开您的程序。(Administrator access.)
替代方法:(Alternative Method:)
或者,您可以使用管理员访问权限打开记事本并使用命令提示符编辑文件。( Command Prompt.)
1.以管理员权限打开命令提示符。(command prompt)在Windows 搜索(Windows search)栏中键入 CMD ,然后(Type CMD)右键单击(right-click)命令提示符并选择Run as administrator。
2.一旦提升的命令提示符(command prompt)打开,您需要执行以下给出的命令
cd C:\Windows\System32\drivers\etc
notepad hosts
3.该命令将打开可编辑的主机文件(host file)。现在您可以对Windows 10(Windows 10)上的 hosts 文件进行更改。
方法 2 - 禁用主机文件的只读(Method 2 – Disable Read-only for the hosts file)
默认情况下,hosts 文件设置为打开,但您不能进行任何更改,即设置为只读。为了修复在Windows 10中编辑主机文件错误时访问(Access)被拒绝,您需要禁用只读功能。
1.导航到 C:\Windows\System32\drivers\etc.
2.在这里您需要找到hosts文件,右键单击(right-click)它并选择Properties。
3.在属性部分,取消选中只读框。(uncheck the Read-only box.)
4.单击应用(Apply),然后单击确定以保存设置
现在您可以尝试打开和编辑 hosts 文件。大概,拒绝访问的问题就解决了。
方法 3 – 更改主机文件的安全设置(Method 3 – Change the Security settings for the hosts file)
有时访问这些文件需要特殊权限。这可能是您可能无法获得完全访问权限的原因之一,因此,您在打开主机文件时遇到拒绝访问错误。
1.导航到C:\Windows\System32\drivers\etc。
2.这里你需要找到hosts文件,右击文件并选择Properties(file and choose Properties)。
3.单击安全选项卡(Security tab),然后单击编辑(Edit)按钮。
4.在这里您将找到用户和组的列表。您需要确保您的用户名(user name)具有完全的访问权和控制权(access and control)。如果您的姓名未添加到列表中,您可以单击“添加”按钮。( Add button.)
5.通过“高级”按钮选择(Advanced button)用户帐户(user account),或者在“输入(Enter)要选择的对象名称(object name)”区域中键入您的用户帐户(user account),然后单击“确定”。
6.如果您在上一步中单击了高级按钮(Advanced button),则单击“立即查找(Find now)”按钮。
7.最后,点击确定并勾选“完全控制”。(checkmark “Full Control”.)
8.单击应用(Apply),然后单击确定以保存更改。
希望(Hopefully)现在您能够毫无问题地访问和编辑主机文件。
方法 4 – 更改主机文件位置(Method 4 – Change the hosts file location )
一些用户指出,更改文件位置(file location)已经解决了他们的问题。您可以更改位置并编辑文件,然后将文件放回其原始位置。
1.导航到C:\Windows\System32\drivers\etc.
2.找到Hosts文件并复制(file and copy)它。
3.将复制的文件粘贴到您可以轻松访问该文件的桌面上。(Desktop)
4.使用记事本(Notepad)或其他具有管理员权限的(Admin access)文本编辑器(text editor)打开桌面上的主机文件。
5.对该文件进行必要的更改并保存更改。
6.最后,将主机文件复制并粘贴(copy & paste)回其原始位置:
C:\Windows\System32\drivers\etc.
推荐的:(Recommended:)
- (Create Multiple Gmail) 无需电话号码验证(Phone Number Verification)即可创建多个 Gmail帐户(Accounts)
- (Identify and Install Missing Audio)在Windows中(Windows)识别并安装缺少的音频和视频编解码器(Video Codecs)
- 修复诊断(Diagnostics) 策略服务(Policy Service)未运行错误
- 解决谷歌浏览器(Google Chrome)页面加载缓慢的(Fix Slow Page Loading)10种方法(Ways)
那是如果您在 Windows 10 中编辑主机文件时成功修复访问被拒绝,(Fix Access denied when editing hosts file in Windows 10) 但如果您对本文仍有任何疑问,请随时在评论部分询问他们。
Fix Access denied when editing hosts file in Windows 10
What is a hosts file in Windows 10?
A ‘hosts’ file is a plain text file, which maps hostnames to IP addresses. A host file helps in addressing network nodes in a computer network. A hostname is a human-friendly name or label assigned to a device (a host) on a network and is used to distinguish one device from another on a specific network or over the internet.
If you have been a tech-savvy person, you would be able to access and modify the Windows hosts file to solve certain issues or block any websites on your device. The hosts file is located at C:\Windows\system32\drivers\etc\hosts on your computer. Since it is a plain text file, it can be opened and edited in notepad. But Sometimes you may encounter ‘Access Denied’ error while opening hosts file. How will you edit the host file? This error will not let you open or edit the hosts file on your computer. In this article, we will discuss various methods to solve Can’t edit the hosts file on Windows 10 issue.
Editing a hosts file is possible and you might need to do it for a variety of reasons.
- You can create website shortcuts by adding a required entry in the hosts file that maps the website IP address to a hostname of your own choice.
- You can block any website or ads by mapping their hostname to the IP address of your own computer which is 127.0.0.1, also called loopback IP address.
Fix Access denied when editing hosts file in Windows 10
Make sure to create a restore point just in case something goes wrong.
Why can’t I edit the hosts file, even as Administrator?
Even if you try to open the file as an Administrator or use the built-in Administrator account to modify or edit the hosts file, you are still unable to make any changes to the file itself. The reason being that the access or permission required to make any changes to the hosts file are controlled by TrustedInstaller or SYSTEM.
Method 1 – Open Notepad with Administrator Access
Most of the people use notepad as a text editor on Windows 10. Therefore, before you edit the host file, you need to run Notepad as Administrator on your device.
1. Press Windows Key + S to bring up the Windows Search box.
2. Type notepad and in the search results, you will see a shortcut for Notepad.
3. Right-click on Notepad and select ‘Run as administrator’ from the context menu.
4. A prompt will appear. Select Yes to continue.
5. Notepad window will appear. Select File option from the Menu and then click on ‘Open‘.
6. To open the hosts file, browse to C:\Windows\system32\drivers\etc.
7. If you can’t see the hosts file in this folder, select ‘All Files’ in the option below.
8. Select the hosts file and then click on Open.
9. You can now see the contents of the hosts file.
10. Modify or make the required changes in the hosts file.
11. From Notepad menu go to File > Save or press Ctrl+S to save the changes.
It is important to note that this method works with all text editor programs. Therefore, if you use another text editor program apart from notepad, you just need to open your program with Administrator access.
Alternative Method:
Alternatively, you can open the notepad with admin access and edit the files using the Command Prompt.
1.Open the command prompt with admin access. Type CMD in Windows search bar then right-click on Command Prompt and choose Run as administrator.
2.Once the elevated command prompt opens, you need to execute the below-given command
cd C:\Windows\System32\drivers\etc
notepad hosts
3.The command will open the editable host file. Now you can make the changes to the hosts file on Windows 10.
Method 2 – Disable Read-only for the hosts file
By default, the hosts file is set to open but you cannot make any changes i.e. it is set to read-only. In order to fix Access denied when editing hosts file error in Windows 10, you need to disable the read-only feature.
1.Navigate to C:\Windows\System32\drivers\etc.
2.Here you need to locate the hosts file, right-click on it and choose Properties.
3.In the attribute section, uncheck the Read-only box.
4.Click Apply followed by OK to save the settings
Now you can try to open and edit the hosts file. Probably, the problem of access denied will be solved.
Method 3 – Change the Security settings for the hosts file
Sometimes getting access to these files requires special privileges. It could be one reason that you may not be given full access, therefore, you are getting access denied error while opening hosts file.
1.Navigate to C:\Windows\System32\drivers\etc.
2.Here you need to locate the hosts file, right-click on the file and choose Properties.
3.Click on the Security tab and click on the Edit button.
4.Here you will find a list of users and groups. You need to ensure that your user name has full access and control. If your name is not added in the list, you can click on the Add button.
5.Select the user account via the Advanced button or just type your user account in the area which says ‘Enter the object name to select’ and click OK.
6.If in the previous step you have clicked on the Advanced button then click on “Find now” button.
7.Finally, click OK and checkmark “Full Control”.
8.Click Apply followed by OK to save changes.
Hopefully, now you will be able to access and edit the hosts file without any issues.
Method 4 – Change the hosts file location
Some users noted that changing the file location has solved their problem. You can change the location and edit the file thereafter put the file back to its original location.
1.Navigate to C:\Windows\System32\drivers\etc.
2.Locate the Hosts file and copy it.
3.Paste the copied file on your Desktop where you can easily access that file.
4.Open the hosts file on your Desktop with Notepad or another text editor with Admin access.
5.Make the necessary changes on that file and save changes.
6.Finally, copy & paste the hosts file back to its original location:
C:\Windows\System32\drivers\etc.
Recommended:
That’s if you have successfully Fix Access denied when editing hosts file in Windows 10 but if you still have any queries regarding this article then please feel free to ask them in the comment’s section.