Confused by a double SSH tunnel, please clear things up :)

pcm81

Senior member
Mar 11, 2011
581
9
81
Good evening all (well, it's evening here :) )

Please help me with setting up ssh tunnels; i am getting confused about local/remote tunnels being connected into a single tunnel.

I have a router with port X open going to SSH port on raspberry pi.
I have a wifi enabled power outlet switch with http gui on port 80

Lets establish some fixed values:
Outside IP is 1.2.3.4.5.6
On router port 123 is open and forwarded to raspberry pi
Raspberry Pi is on a local ip 192.168.0.8 and running ssh server on port 123
Networked power switch is on IP 192.168.0.9 with http gui on port 80

What i want to do is open ssh session to raspberry pi with ssh tunnel from outside of my network via the open port on the router and be able to see the web gui from the wifi enabled power outlet switch.

I have successfully tunnelled into raspberry pi before to open up VNC gui from a remote VNC client, but i am not sure how to set-up ssh tunnel from raspberry pi to the 192.168.0.9:80 to be visible by a client outside of the LAN. Would a tunnel from raspberry pi to http gui be local or remote? Will this work at all?

Thanks ahead
 

mv2devnull

Golden Member
Apr 13, 2010
1,498
144
106
It should.

http://blog.trackets.com/2014/05/17...-port-forwarding-explained-with-examples.html

Local tunneling:
ssh -p 123 -L 8888:192.168.0.9:80 1.2.3.4.5.6

* Apparently establishes an ssh connection to port 123 of the router
* In reality the router forwards, so connection is to RPi
* The ssh client on the outside machine YY listens on port 8888 of the YY
* Packets to http://localhost:8888/ in YY will be taken by ssh, transferred to
sshd in RPi, which will forward them to http://192.168.0.9:80/
* Replies from 192.168.0.9:80 go to sshd@RPi and pop out from localhost:8888 to your browser
 

pcm81

Senior member
Mar 11, 2011
581
9
81
It should.

http://blog.trackets.com/2014/05/17...-port-forwarding-explained-with-examples.html

Local tunneling:
ssh -p 123 -L 8888:192.168.0.9:80 1.2.3.4.5.6

* Apparently establishes an ssh connection to port 123 of the router
* In reality the router forwards, so connection is to RPi
* The ssh client on the outside machine YY listens on port 8888 of the YY
* Packets to http://localhost:8888/ in YY will be taken by ssh, transferred to
sshd in RPi, which will forward them to http://192.168.0.9:80/
* Replies from 192.168.0.9:80 go to sshd@RPi and pop out from localhost:8888 to your browser


Thank you. Will try this tonight
 

imort

Junior Member
Jun 10, 2016
9
0
0
I have successfully tunnelled into raspberry pi before to open up VNC gui from a remote VNC client, but i am not sure how to set-up ssh tunnel from raspberry pi to the 192.168.0.9:80 to be visible by a client outside of the LAN. Would a tunnel from raspberry pi to http gui be local or remote? Will this work at all?
Thanks ahead

Hey

You need to setup an ssh tunnel on the Raspberry Pi first:

Code:
ssh -L 124:192.168.0.9:80 root@pi

It means that you'll run a tunnel on your Raspberry Pi listening on the TCP:124 port.
All requests on that port will be forwarded to the 192.168.0.9:80 which is your switch I believe.

Then you can connect from your PC to Raspberry Pi this way:

Code:
ssh -R 8080:localhost:123 root@your_ip_address

Then you can connect to the address http://localhost:8080 and connect to your power outlet switch.

You can take a look here for more examples with SSH tunneling.