Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a "Nested ssh tunnel"?

Tags:

linux

ssh

sshd

I connect to a linux server over 2 other server:

MyPC --(ssh)--> serverA --(ssh)--> serverB --(ssh)--> FinalServer

httpd is running on FinalServer, listen on 80 serverA/serverB only accept port 22, sshd service

Is there any way to access FinalServer on myPC like this:

myPC> curl http://127.0.0.1:80
Hi , this is FinalServer Httpd Service!!
myPC> 

Thank you a lot!!

like image 582
Wendal Chen Avatar asked Dec 06 '25 05:12

Wendal Chen


1 Answers

In principle, you would only need to tunnel port 80 at every ssh.

So, at every step: ssh -L80:localhost:80 <next-host>.

However, you will not be able to tunnel port 80 (and all ports < 1024) without root privileges, so you'll have to use a different port for this.

like image 71
cornuz Avatar answered Dec 07 '25 21:12

cornuz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!