Communication between two nodes using Java applications using SSH tunnel

I am running an application on a bunch of nodes on a class A network, but can only access them from my own system if I only login to a node on that network that also has a class B address.

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

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

ssh -L 2222:10.10.10.10:22 174.174.174.174

      

EDIT: I used JSch to set up port forwarding from my system to an internal node, but is there a way to make this bi-directional without having to set up a separate tunnel on each internal node? (The nodes are not using the same TCP connection to reply, but have configured new connections to my laptop port 2222.)

+2


source to share


2 answers


If you are asking how to programmatically configure port forwarding, use JSch, which supports port forwarding .



0


source


SSL Tunnel works just like any other socket, you just need to connect to a local socket. In your case it is,

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

      



The tunnel will actually connect at 10.10.10.10:22.

+2


source







All Articles