Windows 主机文件不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17842750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:45:06  来源:igfitidea点击:

Windows hosts file not working

windowsdnshosts-file

提问by Almaron

I need to add a custom IP host line to the hosts file:
c:\windows\system32\drivers\etc\hosts

我需要在 hosts 文件中添加一个自定义 IP 主机行:
c:\windows\system32\drivers\etc\hosts

I tried adding this:
199.229.249.151 models.db

我尝试添加这个:
199.229.249.151 models.db

When I save the file and try to ping the host, the browser cannot find it. I tried using the command line to add read-only to the hosts file -- same result. I tried flushing the DNS cache, but nothing changes.

当我保存文件并尝试 ping 主机时,浏览器找不到它。我尝试使用命令行将只读添加到主机文件 - 结果相同。我尝试刷新 DNS 缓存,但没有任何变化。

What am I forgetting?

我忘记了什么?

采纳答案by user3558019

I ran into same issue and after checking lot of things, the issue ended up being the line endings, I had change the line endings to Windows format and it worked.

我遇到了同样的问题,在检查了很多东西之后,问题最终成为行尾,我将行尾更改为 Windows 格式并且它起作用了。

回答by Hengly

I ran into this problem once, The problem is Windows ignored the host file and I fixed it by:

我曾经遇到过这个问题,问题是 Windows 忽略了主机文件,我通过以下方式修复了它:

  1. Copy the hosts file from C:\Windows\System32\drivers\etcto somewhere like Desktop
  2. Remove the hosts file there
  3. Copy the copied hosts file back to C:\Windows\System32\drivers\etc
  1. 将主机文件从C:\Windows\System32\drivers\etc桌面复制到某个地方
  2. 删除那里的主机文件
  3. 将复制的主机文件复制回 C:\Windows\System32\drivers\etc

I don't know why but it's fixed.

我不知道为什么,但它是固定的。

回答by AndrewRalon

Automatic proxy server configuration scripts override the hosts file. To disable the automatic configuration script:

自动代理服务器配置脚本覆盖主机文件。要禁用自动配置脚本:

  1. Press Windows key and type Configure proxy server
  2. Click LAN settings
  3. Uncheck Use automatic configuration script
  1. 按 Windows 键并键入配置代理服务器
  2. 点击局域网设置
  3. 取消选中使用自动配置脚本

LAN settings

局域网设置

回答by clorz

  1. Try ping localhost.

    if it works, then something wrong with ip or your entry. If it does not, hosts file is bad. Pay attention where it goes. It might try ipv6. That still means that hosts file is broken.

  2. Remove everything from it and leave only your entry or localhost. Single line only, nothing else at all! Not even line breaks. Just stash it aside somewhere until problem is resolved.

    If it works, then there's an entry that breaks things. Try converting line endings to windows format, might help. Usually it's white space that messes with things because it's hard to notice.

  1. 尝试 ping 本地主机。

    如果它有效,那么 ip 或您的输入有问题。如果没有,主机文件是坏的。注意它的去向。它可能会尝试ipv6。这仍然意味着主机文件已损坏。

  2. 从中删除所有内容,只留下您的条目或本地主机。只有单行,没有别的!甚至没有换行。只需将其藏在某处,直到问题解决。

    如果它有效,那么有一个条目会破坏事物。尝试将行尾转换为 windows 格式,可能会有所帮助。通常是白色空间弄乱了东西,因为它很难被注意到。

回答by RCR

Open Notepad > Start Open Notepad > Open as administrator.

打开记事本 > 开始 打开记事本 > 以管理员身份打开。

Save it at some location as ANSI hosts file (Not .txt extension, select all files and name it as hosts)

将其保存在某个位置作为 ANSI 主机文件(不是 .txt 扩展名,选择所有文件并将其命名为主机)

Copy all the hosts files entries and save it.

复制所有主机文件条目并保存。

Finally copy the hosts file copied at the desired location say : C:\tempfolder\hosts to c:windows\system32\drivers\etc folder.

最后将复制到所需位置的主机文件复制到:C:\tempfolder\hosts 到 c:windows\system32\drivers\etc 文件夹。

回答by Li Sirius

I encounter the same issue, and find my host is unicode, after change it to ANSI, the issue is fixed

我遇到了同样的问题,发现我的主机是unicode,改成ANSI后问题就解决了