3

I have 3 machines that are connected as a chain, A,B,C.

 A-->B-->C

A is my machine, B is server, and C is other machine with some services and web server on it. Because of some issues I need access from A to webserver on C (port 80), I can use ssh to login from A to B and then from B to C, but console at this moment is too less. I need web browser, and using ssh with option -X didn't work (some issues with dbus with Firefox start).

I make port forwarding on B using classic command to forward 22 port for ssh:

ssh -L 2222:localhostB:22 user@ipC

but using same to forward port 80 didnt work:

ssh -L 8888:localhostB:80 user@ipC

I know that there is some other forwarding to make it work, but I didn't understand how and what.

I need something like this:

A --> B (frd from B:8888 to C:80) --> C (port 80 web server)

so as effect when I type ipB:8888 I will be forwarded to C:80.

Any help as explain what have to be done, or scripts with command will be appreciated. I notice from one blog that it must be done two times ssh -L forwarding done, but I didn't understand why.

1 Answer 1

5

You're on the right track.

On A:

ssh -L 8888:ipC:80 user@ipB -N

Will make the web server on C accessible via localhost:8888 on A

A bit more details at the OPs request:

I've assumed from your question that you want to access the webserver of C on A (I'm guessing you have a GUI environment on A, with a web browser).

You can't access C directly (for whatever reason), but you can access B, which in turn can access C. So we create a tunnel between A and B, asking B to attach its end of the tunnel to the webserver on C

4
  • could You explain more detail why it is needed on A?
    – Mazeryt
    Jun 17, 2015 at 10:00
  • because it goes through the ssh connection
    – JamesRyan
    Jun 17, 2015 at 12:03
  • 1
    What if C sshd is running on another port? I mean, not on 22
    – geckos
    Aug 21, 2019 at 19:07
  • It does not matter because the sshd on C is not involved here. The ssh connection goes into B. But if the sshd on B is running on port 222 than you add -p 222 to the command.
    – sdittmar
    Jan 21, 2022 at 8:46

You must log in to answer this question.

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