【问题标题】:SSH connection tunneling refusedSSH 连接隧道被拒绝
【发布时间】:2017-08-24 12:33:39
【问题描述】:

我有一个位于专用网络中的虚拟机。 所以首先,我应该进来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 & 

现在我想用netcat 测试ssh-tunnel

我在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

【问题讨论】:

    标签: networking ssh netcat ssh-tunnel


    【解决方案1】:

    每个点对点的 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 & 
    

    【讨论】:

    • 如何解决这个问题?
    • 在答案中添加了更多详细信息。
    • 为什么我需要在第一个连接之前建立第二个连接?
    • 因为你需要将远程协议转发到本地,一旦你建立了第一个连接,在jumphost上,还没有端口可以转发。
    • 关于shot with ProxyCommand:对吗?我有一个错误Connection closed by remote host。值得注意的是my-machine对我来说是不直接可见的。
    猜你喜欢
    • 2019-06-07
    • 2018-01-28
    • 1970-01-01
    • 2021-03-16
    • 2014-05-06
    • 2017-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多