我在
有没有一条命令可以帮助我在打开SSH会话时知道哪个端口正在进行转发?
~/.ssh/config
中配置了许多端口转发,用于不同服务器的VNC。有没有一条命令可以帮助我在打开SSH会话时知道哪个端口正在进行转发?
~/.ssh/config
中配置了许多端口转发,用于不同服务器的VNC。-v
选项来执行ssh
命令,它会显示你正在转发的内容(但同时也会显示一堆其他的调试信息):ssh -v -L2222:localhost:22 remotehost
会向您展示:
...debug messages...
debug1: Authentication succeeded (publickey).
Authenticated to remotehost ([10.0.0.23]:22).
debug1: Local connections to LOCALHOST:2222 forwarded to remote address localhost:22
debug1: Local forwarding listening on ::1 port 2222.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on 127.0.0.1 port 2222.
...debug messages...
然后当您连接到远程shell时,可以输入一个特殊的按键序列:
~#
The following connections are open:
#3 client-session (t4 r0 i0/0 o0/0 fd 7/8 cc -1)
#4 direct-tcpip: listening port 2222 for localhost port 22, connect from 127.0.0.1 port 59742 (t4 r1 i0/0 o0/0 fd 10/10 cc -1)
telnet localhost 2222
以将其转发到remotehost
)。netstat
命令。% netstat -tpln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:2222 0.0.0.0:* LISTEN 28995/ssh
tcp6 0 0 ::1:2222 :::* LISTEN 28995/ssh
netstat
命令可能还会列出其他内容,但你要在输出中查找的是PID/Program
列,以查找ssh
进程,并且要查看Local Address
列,它将显示正在监听哪些端口。在这个例子中,我的机器上IPv4和IPv6接口都在监听端口2222
。
netstat
已经被ss
取代了。 - ScumCoder