tl;dr: A -> B and C -> B works. How to get A->C to work?
I have 3 hosts
A. A local machine
B. A middle-man
C. A phone with a webapp running on port 333
Both A and C can SSH into B. So, A->B and C->B works fine but A -> C does not work.
On B, I can access this webapp at http://localhost:3344
after creating a tunnel from C:
machine-c$ /usr/bin/ssh -f -N -T -R 3344:localhost:333 user@machine-b
I would have thought that with the above tunnel working all I need is a tunnel from A->B like so:
machine-a$ /usr/bin/ssh -f -N -T -L 9999:machine-b:3344 user@machine-b
I can see the following message:
Local connections to LOCALHOST:9999 forwarded to remote address machine-b:3344
But accessing localhost:9999 hangs with the following set of messages being repeated:
debug2: channel 3: zombie
debug2: channel 3: garbage collecting
debug1: channel 3: free: direct-tcpip: listening port 9999 for machine-b port 3344, connect from ::1 port 24626 to ::1 port 9999, nchannels 4
debug1: Connection to port 9999 forwarding to machine-b port 3344 requested.
debug2: fd 10 setting TCP_NODELAY
debug1: channel 3: new [direct-tcpip]
channel 3: open failed: connect failed: Operation timed out
Am not sure whether it's relevant, but since A -> B works, I have also setup a reverse tunnel so that B -> A works too. Ditto for B-> C. So overall the following works:
A -> B
machine-a$ ssh user@machine-b
B -> A (first requires a reverse SSH Tunnel from A->B)
machine-a$ ssh -f -N -T user@machine-b -R1234:localhost:22
machine-b$ ssh -p 1234 user@machine-a
The same has been done for C->B
How can I setup an SSH tunnel from A to C (through B?) so that I can access that webapp directly on A using localhost:3344 ?
I have looked at the following questions but can't wrap my head around what's needed:
SSH as socks proxy through multiple hosts