我有一个默认设置/etc/hosts
,可以在我的 Mac OS X 10.14.4 上将本地主机解析为 IPv4 和 IPv6。
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
然后,我使用 netcat 仅在 IPv4 上绑定一个端口并尝试通过本地主机连接到它。
> sudo nc -4l 80
> netstat -an | grep LISTEN
tcp4 0 0 *.80 *.* LISTEN
我尝试连接到本地主机。
我认为 localhost 使用 IPv6 的第一次尝试将被拒绝,因为没有程序绑定到 IPv6 端口 80,例如
> telnet localhost 80
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
但是,在我的 Mac OS X 10.14.4 上,
> telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.
连接成功但随后就断开了。
有人有同样的问题吗?
谢谢。