【问题标题】:Using an SSH tunnel to accept incoming connections使用 SSH 隧道接受传入连接
【发布时间】:2015-07-02 16:20:06
【问题描述】:

我正在尝试使用 SSH 隧道来完成一些事情,但我尝试在谷歌上搜索“SSH 隧道”并找到关于各种不同场景的讨论,但不是我的场景。

我正在使用计算机 A。我可以通过 SSH 访问计算机 B。我希望计算机 B 运行程序 X,该程序需要连接到计算机 A 上的端口 40000。问题是计算机 B 应用了严格的防火墙我不想修改。我想要的是利用我在计算机 A 到计算机 B 之间通过 SSH 轻松连接的能力,使从 B 到 A 的连接成为可能。

这就是我的设想:我在计算机 A 上运行的程序 Y,它通过 SSH 连接到计算机 B,然后在计算机 B 上侦听端口 40000 上的连接,并通过 SSH 连接转发它们连接到计算机A上的40000端口。然后我在计算机B上配置程序X尝试连接到计算机B上的40000端口,然后它实际上连接到计算机A上的40000端口。

是否有执行此操作的现有程序/SSH 配方?

【问题讨论】:

标签: networking ssh firewall tunnel


【解决方案1】:

我猜你正在寻找 ssh 的 -R 选项:

 -R [bind_address:]port:host:hostport
         Specifies that the given port on the remote (server) host is to be
         forwarded to the given host and port on the local side.  This works
         by allocating a socket to listen to port on the remote side, and
         whenever a connection is made to this port, the connection is for-
         warded over the secure channel, and a connection is made to host
         port hostport from the local machine.
         [...]

【讨论】:

  • 这很棒!后续问题:我想为两组端口创建隧道。我需要运行两个 SSH 命令吗?我试过这个:ssh -R 40000:localhost:40000 -R 40001:localhost:40001 my_host 但它没有用。有什么方法可以用一个 SSH 命令做到这一点?
猜你喜欢
  • 1970-01-01
  • 2021-02-15
  • 2017-08-24
  • 2018-10-06
  • 2016-02-04
  • 1970-01-01
  • 2018-05-05
  • 2011-04-04
  • 1970-01-01
相关资源
最近更新 更多