修改/etc/hosts没有效果

Ros*_*oss 19 networking hostname

我试图阻止自己访问浪费时间的网站,但我对 /etc/hosts.conf 进行了更改。例如:

127.0.0.1   localhost
127.0.1.1   ross-laptop

127.0.0.1   bing.com

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
Run Code Online (Sandbox Code Playgroud)

我可以在新打开的 Chrome 或 Firefox 中访问 bing.com - 为什么这不起作用?

Ric*_*ick 17

您会找到浏览器,系统会为您缓存内容。为了立即应用此功能,您应该确保清除缓存并重新启动浏览器。为了测试这一点,请尝试从终端执行 dns 检查,例如

ping bing.com
Run Code Online (Sandbox Code Playgroud)

你应该得到它从 127.0.0.1 回复。如果这有效,那么您的主机文件更改很好,但它只是缓存在您的浏览器中。


小智 7

您是否尝试将127.0.0.1条目放在同一行上?

120.0.0.1 abc bing.com foo

那应该工作。

  • 这确实有效,尽管我认为这与浏览器缓存它而不是正确清除缓存有关。 (3认同)