SSH tunnel through two servers to access a web service on port 9091

2

1

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

Budius

Posted 2014-06-23T23:19:36.453

Reputation: 147

I need pictures or something. I am not following what needs to go where. In any case, you probably should be using ProxyCommand ssh -W intermediate from the local machine so that you can build a single tunnel between the far host and local host. – Zoredache – 2014-06-23T23:29:04.677

thanks for the answer. I edited the question with some more details. I'll certain check it out ProxyCommand, thanks for the tip – Budius – 2014-06-24T00:02:38.280

I guess the biggest issue I have, is that most examples, have defined hostname/IP. And on my case, I have no idea on REMOTE1 hostname/IP, I need to simply re-use the existing permanent connection on port 16864 – Budius – 2014-06-24T00:16:32.747

and is your PC on LAN1? And do you have any port forwarding set up at the NAT router of LAN1? – barlop – 2015-06-27T16:13:08.517

Hi @barlop that's the old question, I got a new one asking how to do the same on a Chromebook. Yes, PC and LAN are both on the same local network. I have physical and root access on LAN. – Budius – 2015-06-27T16:14:45.737

Answers

3

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

AlexKing

Posted 2014-06-23T23:19:36.453

Reputation: 66

Thanks for the answer. Sounds like it's what I need. I'll only be able to test it later tonight thou, I'll report back. – Budius – 2014-06-24T11:03:30.193

PERFECT!! =] at the end I'm using transmission on the same port it opens and I can use the same technique to expand to any other service I want to run remotely. That was my final command: ssh -L9091:localhost:9091 budius@remote -N (-N at the end to leave the ports open and I can access through the browser) – Budius – 2014-06-24T19:18:52.140