0

I have 2 PCs that I want to connect over the internet with a ssh port forward. The problem is that both PCs dont have a public IP. My Idea was to use a public server (ps) and use ssh -R <port>:localhost:<port> <ps-user>@<ps-address> on PC1.

For PC2 I tried 2 things to create a Connection to PC1: ssh -p <port> <pc1-user>@<ps-address> and ssh -L <port>:localhost:<port> <pc1-user>@<ps-address>. But both do not result in an ssh connection to PC1.

What do I do wrong here?

Addition: Please note that I can not port forward on both PC1 and PC2

  • You may use the router's public IP, but only for connecting from outside the network (no round trips), setting up port forwarding on the router. Otherwise, your post is very unclear - could you substitute values for <port> etc. and report on your operating systems and local network architecture? – harrymc May 22 '18 at 9:59
  • Sure, the Port is 5900. The background is that I have a ubuntu device (PC1) that is in an unknown network (the device travels from location to location, most of the time it will just be a single router + the device in the network but I have no way to configure the router to forward a port for me). I want to be able to establish a encrypted vnc session using ssh and x11vnc from any Windows PC (PC2, this one also changes the location but is never in the same lan as PC1) to the device PC1 (PC1 is running x11vnc). – Teekeks May 22 '18 at 10:12
0

So, if I understood your question, you have:

  • 2 PCs on internal networks.
  • You have no influence on the routers on either network.

And you want to:

  • Set up a public server (PS) hosting an SSH service (I assume port 22).
  • Connect PC1 and PC2 to PS (Outgoing traffic, no router config).
  • Connect a VNC session from PC2 (Windows) to PC1 (Ubuntu) on port 5900.

You can achieve that by creating an SSH tunnel, doing a remote forwarding from PC1 and a local forwarding from PC2.

This would be the architecture:Architecture diagram

So to get this working, from the Ubuntu PC, PC1, you need to connect to PS using:

ssh <ps-user>@<ps-address> -R 5901:localhost:5900

At this point if you logged into the PC1 you may run netstat -latn | grep 5901 and you should see it listening. This means that one half of the process is ready.

Now the client connection. From PC2, if it was a linux box too, you might use

ssh <ps-user>@<ps-address> -L 5902:localhost:5901

if it is Windows, you can use PuTTY, by setting the port forwarding section below Connection / SSH / Tunnels, and add a Local port with Source port 5902 and destination localhost:5901. When clicking add you will see in the list of forwarded ports something like L5902 localhost:5901

Now you have two tunnels connected to a public server. If you run VNC viewer from PC2 and point to localhost:5902, you should connect to the VNC service listening on port 5900 on PC1.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.