127.0.0.1 和 ::1 都应该包含在 /etc/hosts 文件中吗?

fil*_*eha 8 hosts-file

我是非托管 VPS 服务器以及 IPv6 的新手。对于启用 IPv6 的服务器,是否有必要在 /etc/hosts 文件中为 localhost 包含 127.0.0.1 AND ::1 ,或者仅 ::1 就足够了?

Sir*_*rch 8

是的,应该留下 127.0.0.1。IPv6 已启用,但仍使用 IPv4。


Mas*_*imo 5

您没有提到您使用的是哪个操作系统。

在 Windows 系统上,名称解析localhost由系统处理,hosts文件中不需要这些条目。这甚至在同一个文件中明确提到:

# localhost name resolution is handled within DNS itself.
#   127.0.0.1       localhost
#   ::1             localhost
Run Code Online (Sandbox Code Playgroud)