当我发出 nc -v 命令时,我想 telnet 到我本地运行的 VM 中,该 VM 有一个在端口 2628 上运行的 dictd 服务,尽管我得到以下信息:
$ nc -v localhost 2628
nc: connectx to localhost port 2628 (tcp) failed: Connection refused
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src 127.0.0.1 port 63929
dst 127.0.0.1 port 2628
rank info not available
TCP aux info available
Connection to localhost port 2628 [tcp/dict] succeeded!
Run Code Online (Sandbox Code Playgroud)
为什么连接被拒绝,然后连接成功?这是什么意思,为什么当我这样做时它不接受我的连接:telnet localhost 2628
?
phe*_*mer 13
有几十个版本的 netcat 可用,但这可能是因为:
localhost
in /etc/hosts
。一个用于 IPv4,另一个用于 IPv6。例如:
$ grep localhost /etc/hosts
127.0.0.1 localhost
::1 localhost
$ nc -4 -l -p 9000 -s 127.0.0.1
nc: listening on 127.0.0.1 9000 ...
$ nc localhost 9000
nc: cannot connect to localhost (::1) 9000 [9000]: Connection refused
nc: localhost (127.0.0.1) 9000 [9000] open
nc: using stream socket
Run Code Online (Sandbox Code Playgroud)