1

I'm wondering if/how I can realize the following setup. It doesn't seem to fit the standard ssh port forwarding model.

I have a client machine A. I have a server application running on machine A, which listens on port X. However, machine A is behind a common IP-address (shared by many users) so it can't receive incoming connections to port X from the internet. However, I have access to a machine, B, in Amazon EC2 and it would be OK connections would go through that machine. It's not possible to move the application to this machine in EC2.

Hence, what I want, is to have machine B listen on port X and forward all connections/communications to machine A. Machine A has to see it as if clients are connecting to port X in the usual way (it would be acceptable that the source IP appears as machine B).

The solution must work in such a way that machine A is the client that connects to machine B. So in the case of ssh, A would have to be the ssh client and B the ssh server. Again, this is because machine A is behind the common IP, hence all connections have to be outgoing from A.

How can this setup be realized? Preferably using commonly available and free software? Thank you in advance.

1 Answer 1

1

This can be easily done by with a ssh reverse connection, started on Machine A. As a pointer this should be helpfull

ssh -R :PortX:127.0.0.1:PortX user@MachineB

If you run windows on "Machine A" plink is an alternative to ssh (client).

However, persistent reverse-port-forward can be tricky, but absolutely possible.

On "Machine B" you need to have enabled

GatewayPorts clientspecified 

in sshd_config

EDIT:

  • the ":" (colon) in front of PortX is needed to make the Port available to 0/0
  • GatewayPorts clientspecified enables this feature. GatewayPorts Yes always makes the reverse forwareded port world reachable.
3
  • Hi thanks I had never heard of ssh reverse connections before and I couldn't find it when searching for the keywords related to my problem. Thanks so much!
    – Morty
    Jan 5, 2013 at 21:20
  • you are welcome! please upvote my answer. Jan 5, 2013 at 23:36
  • I would very much like to upvote it, but I need 15 reputation points for that. Sorry!
    – Morty
    Jan 6, 2013 at 18:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .