使用 SSH 隧道运行 Java 应用程序的两个节点之间的通信

发布于 2024-08-04 02:36:06 字数 531 浏览 2 评论 0原文

我正在 A 类网络中的一堆节点上运行应用程序,但如果我登录到该网络中唯一也具有 B 类地址的节点,则只能从我自己的系统访问它们。

但是,客户端部分(带有 GUI 和所有内容)只能在我的系统上运行,因此我需要某种与 A 类网络进行通信的方式。客户端(我的系统)尝试与服务器(位于内部网络边缘,使用 ServerSocket)建立一个简单的 TCP 套接字,但收到“连接超时”异常。由于仅开放 SSH 端口 22,因此有人建议我使用 SSH 隧道将数据包从我的系统发送到内部网络。

经过一番谷歌搜索后,我发现以下内容允许您设置 SSH 隧道,但是我如何在 Java 中使用它来设置套接字以及什么不是呢?谢谢!

ssh -L 2222:10.10.10.10:22 174.174.174.174

编辑: 我已经使用 JSch 设置从系统到内部节点的端口转发,但是有什么方法可以使其双向,而不必在每个内部节点上设置单独的隧道? (节点不使用相同的 TCP 连接来响应,但已建立到我笔记本电脑端口 2222 的新连接。)

I'm running an application on a bunch of nodes in a class A network, but can only access them from my own system if I log into the only node in that network that also has a class B address.

However, the client portion (with the GUI and everything) can run only on my system, so I need some way of communicating with the class A network. The client (my system) attempts to set up a simple TCP socket to the server (at the edge of the internal network, with a ServerSocket), but gets a Connection Timed Out exception. Since only the SSH port 22 is open, someone recommended I use SSH tunneling to send packets from my system to the internal network.

After a bit of Googling, I see that the following allows you to set up an SSH tunnel, but how would I use this from within Java to set up the sockets and what not? Thanks!

ssh -L 2222:10.10.10.10:22 174.174.174.174

EDIT:
I have used JSch to set up port forwarding from my system to an internal node, but is there any way I can make it bidirectional without having to set up a separate tunnel on every internal node? (The nodes aren't using the same TCP connection to respond, but have set up new connections to my laptop's port 2222.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

[浮城] 2024-08-11 02:36:06

SSL 隧道的工作方式与任何其他套接字一样,您只需连接到本地套接字即可。在您的情况下,

Socket socket = new Socket("localhost", 2222);
OutputStream out = socket.getOutputStream();

隧道实际上会连接到 10.10.10.10:22。

SSL Tunnel works just like any other socket, you just need to connect to the local socket. In your case, it's,

Socket socket = new Socket("localhost", 2222);
OutputStream out = socket.getOutputStream();

The tunnel will actually make a connection to 10.10.10.10:22.

烏雲後面有陽光 2024-08-11 02:36:06

如果您询问如何以编程方式设置转发端口,请使用支持端口转发的 JSch

If you're asking how to programatically set up the forwarded ports, use JSch which supports port forwarding.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文