Take the 2-minute tour ×

In my home network I have a PC, raspberry pi, macbook and a few other devices which I want to access away from home.

As it stands, I have setup VNC server on my PC along with remote desktop and have changed the default ports. These ports are open on my router and redirect to the PC so that I can access them via dynamic dns.

However I was wondering if it was possible to close those open ports on the router, and instead leave only port 22 on the raspberry pi so I can use an SSH tunnel through the pi, to the PC and run VNC through that?

If so how would the command prompt look? I understand vaguely how SSH tunnels work and can use them applying to 1 remote host, i.e:

ssh -L 22222:localhost:5900 user@pi

then running localhost:22222 in my vnc viewer will let me connect to the pi.

Reading up on the subject suggests I could do something like ssh -L 22222:internal_pc_ip:5900 user@pi and run localhost:22222 like before?

Can I do this?

share|improve this question
I think you'll need an uppercase -L in your ssh command to establish tunnel. –  Ketan Feb 5 at 18:45
You're right, sorry about that it completely slipped my mind. –  gray_fox Feb 5 at 18:50

1 Answer 1

up vote 1 down vote accepted

Your approach looks ok to me.

If so how would the command prompt look?

You will actually be connected to your pi after the ssh -L command. You will get the prompt that you have on your pi device. Keep this connection open to forward all the traffic from localhost:5900 of your pi device to port 22222 of the device from where you are ssh'ing. To have multiple tunnels, I think you will need a new localport. So, may be replace 22222 with 33333.

share|improve this answer
Thanks, appreciate the help! –  gray_fox Feb 5 at 19:19

Your Answer


