要创建到远程主机上运行的本地网络服务的 SSH 隧道,我需要什么?

要创建到远程主机上运行的本地网络服务的 SSH 隧道,我需要什么?

我想将 virtualbox 计算机连接到远程计算机上的本地服务。我可以连接到本地服务,但在远程服务上,我遇到了问题,因为在目标上,该服务在本地 LAN 中运行。

这是第 3 台计算机和第 3 台计算机上的两个接口的图形。我想连接到 10.0.0.8:200,因为我想连接的服务仅在远程计算机上的本地网络上运行。

+--------------------+
|                    |
|  VirtualBox        |
|  192.168.11.11:200 |
|                    |
+-----+--------------+
      |
      v
+--------------------+
|                    |
|  Local Computer    |
|  192.168.11.41:200 |
|                    |
+-----+--------------+
      |
      v
+--------------------+
|                    |
|  Remote Computer   |
|  8.8.8.8           |    <- I can connect here
|                    |
|  10.0.0.8:200      |    <- how do I connect here?
|                    |
+--------------------+

我能够在本地计算机和远程计算机之间打开隧道,但这并没有给我提供连接到本地网络 10.0.0.8 上的服务的方法。

到目前为止,我所拥有的是本地计算机和远程计算机之间的 SSH 隧道。我可以在 VirtualBox 和本地计算机之间进行连接(我有一个桥接网络设置,可以按预期工作。)

ssh -L 200:8.8.8.8:200 example.com

所以我缺少的是 8.8.8.8 和 10.0.0.8 之间的连接。如何在两者之间创建隧道/代理,使 10.0.0.8:200 上的服务可供我的本地计算机使用?

答案1

首先,你的命令有一个明显的错误。您的程序仅在本地网络上运行,但您正在使用 转发连接到公共 IP -L 200:8.8.8.8:200。所以你应该改用-L 200:10.0.0.8:200

其次,通过使用,ssh 客户端默认-L 200:10.0.0.8:299只会监听。localhost:200可以使用 选项来配置此行为GatewayPorts。要明确告诉 ssh 客户端接受来自其他主机的连接,您可以使用-L 0.0.0.0:10.0.0.8:200.从man ssh_config

     GatewayPorts
             Specifies whether remote hosts are allowed to connect to local forwarded ports.  By default, ssh(1) binds local port forwardings to the loopback address.  This
             prevents other remote hosts from connecting to forwarded ports.  GatewayPorts can be used to specify that ssh should bind local port forwardings to the wild‐
             card address, thus allowing remote hosts to connect to forwarded ports.  The argument must be yes or no (the default).

相关内容