【问题标题】:SSH tunnel via multiple hops通过多跳的 SSH 隧道
【发布时间】:2021-10-28 23:30:46
【问题描述】:

我有 1 个客户端(Windows 操作系统)和 4 个 VPS(Linux 操作系统)。

我想创建带有 ssh 隧道的 Socks v5 代理,用于将客户端连接到 VPS-4。

客户端 -> VPS-1 -> VPS-2 -> VPS-3 -> VPS-4 -> 互联网

在使用 CMD 的客户端中,我使用命令连接到 VPS-1:

ssh -L9999:localhost:9999 root@VPS-1-IPaddress

在 VPS-1 ssh 窗口内:为了将 VPS-1 连接到 VPS-2,我使用命令

ssh -Dlocalhost:9999 root@VPS-2-IPaddress

在 VPS-2 ssh 窗口内:为了将 VPS-2 连接到 VPS-3,我使用命令

ssh -Dlocalhost:9999 root@VPS-3-IPaddress

在 VPS-3 ssh 窗口内:为了将 VPS-3 连接到 VPS-4,我使用命令

ssh -Dlocalhost:9999 root@VPS-4-IPaddress

当我在浏览器代理设置中设置“localhost”和端口“9999”并打开网站whatismyipaddress 我看到了 VPS-2 IP 地址。

我必须看到 VPS-4 IP 地址。我不知道是什么问题。

谁能给我建议?

【问题讨论】:

    标签: ssh proxy ssh-tunnel socks tunnel


    【解决方案1】:

    手工工作太多。

    使用 ~/.ssh/config 文件时

    HOST VPS-4-IPaddress
      user root
      ProxyJump VPS-3-IPaddress
    
    HOST VPS-3-IPaddress
      user root
      ProxyJump VPS-2-IPaddress
    
    HOST VPS-2-IPaddress
      user root
      ProxyJump VPS-1-IPaddress
    
    HOST VPS-1-IPaddress
      user root
      ProxyJump VPS-2-IPaddress
    

    也可以将代理链接在一行中

    HOST VPS-4-IPaddress
      user root
      ProxyJump VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress
    

    然后就可以使用了

    ssh -D9999 root@VPS-4-IPaddress
    

    或者没有.ssh/config文件,直接在命令行上(-J等于-o ProxyJump=

    ssh -D9999 VPS-4-IPaddress -J VPS-1-IPaddress,VPS-2-IPaddress,VPS-3-IPaddress
    

    手动方式

    您需要构建从一台机器到另一台机器的本地转发。
    socks 代理只会在最后一个上定义。

    客户端:> ssh -L9999:localhost:9999 root@VPS-1-IP地址

    VPS-1:> ssh -L9999:localhost:9999 root@VPS-2-IP地址

    VPS-2:> ssh -L9999:localhost:9999 root@VPS-3-IP地址

    VPS-3:> ssh -D9999 root@VPS-4-IP地址

    但隧道与自动变体或多或少相同。

    【讨论】:

    • 是的 手工工作太多。但我需要像我这样的方法。你知道我的方法有什么问题吗?
    • @miki 我为您的手动方式添加说明。
    • ty 回答,我在一行中使用此命令: ssh -L9999:localhost:9999 root@VPS-1_IP -t ssh -L9999:localhost:9999 root@VPS-2_IP -t ssh - L9999:localhost:9999 root@VPS-3_IP -t ssh -L9999:localhost:9999 root@VPS-4_IP -t ssh -Dlocalhost:9999 root@VPS-5_IP 在这个命令之后我一一输入VPS密码。我可以在上面的命令中输入密码吗?
    • @miki 你应该使用公钥/私钥,然后你不需要输入密码
    • 好的,谢谢。有可能我的方法还是我应该使用公钥/私钥?
    猜你喜欢
    • 2011-12-14
    • 2016-09-09
    • 2014-09-03
    • 2013-05-26
    • 2013-09-28
    • 2012-08-15
    • 2018-09-02
    • 2019-01-12
    • 1970-01-01
    相关资源
    最近更新 更多