我在一个专用网络中有一台虚拟机。所以,首先,我应该进入server.com,然后进入my-machine。
我想把ssh-tunnel从我的笔记本电脑变成my-machine。
ssh -v -A -nNT -L 40000:127.0.0.1:40000 login@server.com ssh -v -nNT -L 40000:127.0.0.1:40000 my-machine & 现在我想用ssh-tunnel测试netcat。
我在my-machine跑步
nc -l 40000在我的笔记本电脑上:
~ ❯❯❯ nc 127.0.0.1 40000但它给了我:
debug1: Connection to port 40000 forwarding to 127.0.0.1 port 40000 requested.
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: connect failed: Connection refused
debug1: channel 2: free: direct-tcpip: listening port 40000 for 127.0.0.1 port 40000, connect from 127.0.0.1 port 49692 to 127.0.0.1 port 40000, nchannels 3为什么会发生这种情况,以及如何解决?我希望我在笔记本电脑控制台中输入的任何内容都会出现在my-machine控制台中。
最后一根绳子是什么意思?特别是127.0.0.1 port 49692,为什么使用这个端口?我从不打字。
debug1: channel 2: free: direct-tcpip: listening port 40000 for 127.0.0.1 port 40000, connect from 127.0.0.1 port 49692 to 127.0.0.1 port 40000, nchannels 3发布于 2017-03-30 14:16:48
每个TCP连接都需要两对IP地址和端口。阅读所有的信息(不仅仅是你展示的部分):
connect from 127.0.0.1 port 49692因此,您确实是在连接到端口40000,但是您正在从端口49692连接(为您的netcat或一些转发的步骤随机分配)。
如何解决这个问题?
这种双跳转发不起作用,因为您需要在第一个转发之前建立第二个。
此外,您还对第一个命令使用-N开关,这将阻止运行第二个ssh命令。
但是我会尝试使用ProxyCommand,这将使您可以直接从主机上使用单个命令连接到目的地:
ssh -v -nNT -L 40000:127.0.0.1:40000 \
-oProxyCommand="ssh -W %h:%p login@server.com" my-machine & https://stackoverflow.com/questions/43120316
复制相似问题