We did a post about reverse ssh tunneling post, which is in spanish (we might redo it in english… or not), so this is part 2.
The main idea of the Part 1 was to make a reverse ssh tunnel to access remotely a server in a private network and the network staff won’t allow us to access it directly.
Let’s say we have a remote server we want to access (http or ssh) but this server is in a local network and doesn’t have internet access, we will call it Server_1 and its local IP is 172.20.1.1. Then we have our local PC, called Local_PC, which has internet connection and our public IP is 126.96.36.199. If we want to access directly to Server_1 we won’t be allowed since it doesn’t have internet connection.
Then when we need to access the server, the client in the remote network provides us with a Teamviewer connection though a Laptop running windows, what can we do to access directly from our Local_PC running our beloved Linux?
Yes, we can use Putty to make a reverse ssh tunnel from Server_1 to Local_PC, but how do we do so?
You open up Putty in the laptop and go to Connection -> SSH -> Tunnels then you have to input the Source Port which will be Local_Pc: 188.8.131.52:<remote_port> (be sure not to use an already occupied port). Then in Destination we input 172.20.1.1:22 for ssh or 172.20.1.1:80 for http or whatever port you need. Change the checkbox from Local to Remote, since we are doing a reverse tunnel, and simply click Add. Finally go back to the Session section and connect to Local_PC via ssh and voilá!
You will be able to access Server_1 from Local_PC simply doing:
ssh user@localhost -p <remote_port>
It is possible to Add more tunnels with a single connection, so you can tunnel an ssh connection and a http one.