SSH Tunnel – Accessing Web Service Through Two Servers

linuxnetworkingsshssh-tunneltunnel

what I have is a "phone-home" service running at remote1 that connects to LAN1 via:

ssh -N -R 16864:localhost:22 <myuser.on.lan1>@<lan1.ip>

so from the SSH terminal on LAN1 I can easily load terminal on remote1 doing:

ssh -l <myuser.on.remote1> -p 16864 localhost

remote1 is running a daemon service with a web panel on port 9091 (Transmission).

So what I want is to connect to this web interface on port 9091 on remote1, through LAN1 (that already have a tunnel open on port 16864) from my local machine.

so probably this:

Local machine browser -> LAN1:16864 -> 22:REMOTE1:9091

I've been trying quite a few different SSL commands based on what I read HERE, HERE, HERE and the original setup is based on THIS

I've been trying stuff like this, but I'm sure I'm close but pretty lost on what to do:

ssh -t -L8080:localhost:5590 user@192.168.2.42 ssh -l user -p 16864 localhost -N

but of course, if I'm asking here it's because I'm failing miserably. Any expert to help me out on this one?

edit:

I don't have any diagrams but I'll explain in a different way:

I have 3 linux computers:

  • REMOTE1 always-on raspPi on remote location, which I don't have much access to network configuration
  • LAN1 always on raspPi on my local lan, where I can setup port-forwarding, fixed IP and dynamic DNS, without issues.
  • my PC, which I want to be able to access web services on REMOTE1

REMOTE1 is doing a "call home" to keep a SSH connection with LAN1 via:

ssh -N -R 16864:localhost:22 <myuser.on.lan1>@<lan1.ip>

and that part is working fine. I use my local machine terminal to SSH to LAN1, then inside LAN1 machine I type:

ssh -l <myuser.on.remote1> -p 16864 localhost

and I can do terminal stuff on REMOTE1.

Currently I only got a service on 9091 (transmission-daemon) but I'll be installing some other stuff later.

So the question, how do I tunnel from my local machine to access the web service on port 9091 on the REMOTE1 going through the tunneled connection on LAN1?

in a simplistic way:

  • local machine: ssh 8888 <magic> 1684 <magic> 9091 <magic> -N
  • open the browser on type localhost:8888/transmission/web/ and access it the transmission-daemon on REMOTE1

Best Answer

First set up so you can ssh from your PC "directly" to remote1:

In your .ssh/config put:

Host remote1
  Proxycommand ssh -q -l <myuser.on.lan1> lan1 nc -w 600 localhost 16864

Make sure netcat (nc command) is installed on lan1.

You should now be able to ssh from your pc with:

ssh <myuser.on.remote1>@remote1

once this works, use:

ssh -L8888:localhost:9091 <myuser.on.remote1>@remote1

and you have access to transmission on remote1:9091 via localhost:8888

Related Question