Ssh port forwarding (tunneling) in linux

I have a specific scenario that I want to solve. I am currently connecting to the host through port forwarding:

laptop -> gateway -> remote_server_1 

and another host:

  laptop -> remote_server_2 

using a password without a password working on both. None of the remote servers appear in the outside world. Now I start the service on remote_server_2 that I would like to have access to remote_server_1. I assume that I need to configure reverse port forwarding from remote_server_1 to my laptop and then to remote_server_2, but I'm not sure how to do this. Has anyone encountered this situation before?

Edit: Complete solution in case someone needs it:

 mylaptop$ ssh -L 3001:localhost:3000 server_2 server_2$ netcat -l 3000 

Then configure the tunnel through gateway on server_1 :

 ssh -t -t -L 3003:server_1:22 gateway 

Then go to it from server_1 :

 ssh -R 3002:localhost:3001 -p3003 localhost echo "bar" | nc localhost 3002` 

and hey presto server_2 shows bar server_2

+6
source share
1 answer

You must do what you have described. Install the server on server_2 .

 mylaptop$ ssh -L 3001:localhost:3000 server_2 server_2$ netcat -l 3000 

Then access it from server_1 .

 mylaptop$ ssh -R 3002:localhost:3001 server_1 server_1$ echo "foo" | netcat localhost 3002 

server_2 display foo .

+4
source

Source: https://habr.com/ru/post/901205/


All Articles