1

I am having a aws server(10.10.10.1) which will act as a CISCO Router and it will port forward to another aws server(10.10.10.2). Now I am connecting a server in ssh using the following command.

ssh -i server.pem ec2-user@10.10.10.1 -p 2222

Then it will connect to the Server 10.10.10.2.

Now I need to run a socket program there and I need a client(Which will run in local) program to connect that.

I tried in many ways but I am not able to connect that.

I am new in socket programming please help me to sort out.

Below Answer Result:

I have tried to connect through the SSH tunnel and the tunnel is working for the router and it is not going to the aws server

Please see my tunnel command,

ssh -i server.pem -L 9080:10.10.10.2:8090 ec2-user@10.10.10.1

I also ran a Socket server code in 10.10.10.2 and the client code in my local machine.

Please help me to sort it out

samaswin
  • 384
  • 1
  • 2
  • 21
  • This might be helpful http://stackoverflow.com/questions/8167512/java-socket-port-forwarding And http://stackoverflow.com/questions/3954454/fast-implementation-of-a-port-forward-in-java – Anil Feb 27 '16 at 08:11

1 Answers1

2

This is your layout

DEV ---ssh---> PIVOT ---ssh---> SERVER

There's an SSH feature called port forwarding that allows the user to open a listening (server) socket on one end of the connection (-L for local, -R for remote) and proxy all socket reads and writes to another machine reachable from that end.

Since PIVOT can connect to SERVER you simply need a proxy on your DEV machine:

me@dev$ ssh -L 9005:server:80 pivot

And then when you talk to localhost:9005 on the development machine you are in fact talking to server:80 via the SSH channel.

Note: if host A can't directly connect to the server and you use it to ssh into B that can, you actually have to setup two forwards, one for each SSH bridge.

Raffaele
  • 20,627
  • 6
  • 47
  • 86
  • It is asking some password to setup the tunnel. I am using pem key to connect. Can I give pem key in -i comment. Also Do I need to add both servers pem files? – samaswin Feb 27 '16 at 12:40
  • Hi,I have tried the SSH tunnel and I am to connect to the end server. When I run the socket code the client is connecting to the user however the server is not responding – samaswin Feb 27 '16 at 13:48
  • I can't understand the downvote. It's not my fault that you can't type the right parameters on the command line. – Raffaele Feb 27 '16 at 16:21
  • Please update the answer. I wrongly downgrade and I was not able to upgrade that again. it is asking to edit the answer – samaswin Feb 27 '16 at 17:04
  • Ok. See if the note helps – Raffaele Feb 27 '16 at 17:18
  • Ok. But the second PIVOT is a router. So the router command only works in that. Is it possible to do that – samaswin Feb 27 '16 at 17:24
  • Sorry, can't understand the problem. Please try to update the answer by detailing your current workflow, which machines are involved (batter use actual domain names), what OS they run and what commands you can run – Raffaele Feb 27 '16 at 17:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104741/discussion-between-samaswin-and-raffaele). – samaswin Feb 27 '16 at 18:10