这个 netcat 输出是什么意思?

这个 netcat 输出是什么意思?

我想远程登录到本地运行的虚拟机,该虚拟机在端口 2628 上运行 dictd 服务,当我发出 nc -v 命令时,尽管我得到以下信息:

$ 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!

为什么连接被拒绝,后来又连接成功了?这是什么意思,为什么当我这样做时它不接受我的连接:telnet localhost 2628

答案1

netcat 有几十个版本可用,但这可能是因为:

  1. 您有 2 个条目localhostin /etc/hosts。一个用于 IPv4,另一个用于 IPv6。
  2. 该守护进程仅侦听一种协议(可能是 IPv4)。
  3. 客户端首先通过守护进程未侦听的协议进行连接,然后尝试它所在的协议。

例如:

$ 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

相关内容