ssh tunnelling port forwarding

I have three computers, A, B, C. A is the computer I'm working on, C is the remote computer I'd like to access. However C can only be accessed through B. Only B has a ssh server, and only A has a ssh client.

What command am I to use (preferably on A) so that I can connect to C (port 80) through B ? For example B should forward all incoming port 12345 to C:80.

I know this is a common question and I found a ton of commands on google but none seemed to work.

Once it is set up, I'm supposed to just use localhost:5678 on A, which connects to B:1234, and then forwards to C:80.

Thanks.


Solution 1:

It might be that the sshd daemon is set to disallow port-forwarding to other machines or to disallow port-forwarding at all. Anyway, the correct command to issue at A to access C at port 80 as follows:

ssh -L localhost:5678:<ip-or-name-of-C>:80 <ip-or-name-of-B>

After the ssh session is established you connect to localhost:5678 to get connected to C:80. If you wish any inbound connection to the host A:5678 be forwarded to C:80, then remove localhost: from the command above.

If the port-forwarding to other hosts is disabled at B, then you could try the chaining, described here