0

So, if I want to access my (Raspberry Pi) desktop remotely but from within my LAN, that works just fine via VNC (VNC server integrated into the Raspberry OS, VNC Viewer installed on controlling device). How can I send instructions from a second PC (outside the LAN) to my raspberry VNC server (what they call establishing a cloud connection) without having to make the VNC server accessible from the internet? It works, but does it work without forwarding?

And yes, an authentication on the raspberry is needed when establishing a connection, but still, how can this work without forwarding ports?

13
  • there is such a thing as a reverse connection, but that still involves forwarding ports, instead of the viewer computer initiating a connection to the viewed(and the viewed computer running a server and the NAT router near the viewed server having port forwarding done to the viewed computer).. In a reverse . connection the viewed computer initiates a connection, and the viewer computer's router has to have port forwarding set up. So it is done when a technical person wants to view somebody elses computer, the techie takes on the burden of port forwarding.
    – barlop
    Commented May 29, 2022 at 21:04
  • also many people use teamviewer rather than vnc.. so as to avoid port forwarding!
    – barlop
    Commented May 29, 2022 at 21:04
  • @barlop so you're saying there is port forwarding being done but by the intermediate RealVNC server? What I do not fully understand is how in such a reverse connection this server manages to control my viewed computer, as this would require it to be accessible from outside right? And secondly how does teamviewer work exactly then? Commented May 29, 2022 at 21:31
  • In regard to your question re intermediate server and reverse connection. In a reverse connection, there is no "intermediate" server.. it's just that instead of A connecting to B, B connects to A. So there is still port forwarding it's just on the viewer end rather than the viewed end.
    – barlop
    Commented May 29, 2022 at 23:19
  • In regard to your question of how it's possible for a computer to be controlled and wouldn't that require it to be accessible from outside. Well, when you browser the internet you don't forward any ports at your end but your computer is still controlled by your web browser / whatever software is on it. You are at the mercy of whatever programs are on your computer!
    – barlop
    Commented May 29, 2022 at 23:20

2 Answers 2

0

Use ZeroTier. It creates a virtual LAN over any network, including the Internet.

You have to install the clients on all devices and connect them to the same virtual network. That's it - ZeroTier will take care of making the connection.

It uses "hole punching" technique to open ports without permanent forwarding. 3rd party servers are used to punch the hole in firewalls and NATs. All subsequent communication is DirectX.

The free plan should be more than sufficient for your needs.

0

One easy way that is used by eg a technical family member to fix somebody's computer remotely, is called teamviewer. No port forwarding required on your router.

There are probably a number of easy ways.

Another way is SSH. And you can VNC through that. Though you'd have to know a bit about SSH.

No port forwarding required on your router.

You can use an intermediary computer.

so let's say you have 2 computers

A and B that want to connect to each other, and now add a third computer, X that is the intermediary.

X could be a VPS. A virtual machine, hosted by some company like digitalocean. That can be set up with some clicks. That has an open port on it, port 22, running SSH.

Now, you connect A to X, and you connect B to X. X is running SSH on port 22. So A and B connect to X with SSH client software. The ssh client software is typically the command ssh.

B should connect to X, with the SSH option that a port should be opened on X, and anything received on that port, should be forwarded to B. This can be done with SSH -R.

A should connect with the SSH option that A shall open a port, and anything received on that port, will be forwarded to that port that B opened on X.

A then connects VNC viewer to A, which goes to X, which goes to B.

That is quite an advanced use of SSH. And SSH is quite a complex tool.

Some pre-requisite knowledge I would suggest is normal use of SSH, by which I mean without -L or -R. Knowing about passwordless login / ssh keys, is good too. Good to know a bit of SFTP in the process just to transfer files from one system to the other. After that, use of ssh -L , then ssh -R with just two computers, no intermediary.

ssh -L and ssh -R are for tunneling. The idea of encapsulating one protocol in another protocol, where the encapsulating protocol is encrypted, or encrypts. And the encapsulated protocol becomes encrypted by the encapsulating protocol.

Technically a person could set up what looks like an HTTPS Server because it runs TLS protocol on port 443, but actually could be a VNC server there encrypted within TLS. So if they were in a university that blocked a lot, the university might allow out traffic on port 443 for people to browser the web. There are programs stunnel and corkscrew that can help with that.

For the sake of learning SSH and use of -L and -R, as pre-requisite knowledge. Part of my answer here mentions those. SSH Tunneling in Layman's term

So now getting back to how to do what you want to SSH.

A.. runs VNC viewer/client.

B.. runs VNC server (the viewed).

X is e.g. a VPS.

B$ ssh -R 40500:127.0.0.1:5901 user@hostX

(that line above has connected B to X, and has opened up port 40500 on X. and anything received there will be forwarded to B's VNC server).

A$ ssh -L 1234:127.0.0.1:40500 user@hostX

(the line above connects A to X. And it has opened up port 1234 on X, and anything received there goes to X and is forwarded to 127.0.0.1:40500)

Then from A, you connect VNC Viewer to port 1234

I've done this very recently.. and the computer where my VNC server is, is in a place with no ISP cable or telephone line. So I have a router with a SIM card in there. (I guess nowadays not only are phones computers, but phone providers are ISPs!). So this router has a SIM card in it. But the connection drops for a moment quite frequently. So I have a bash while loop one-liner, around the SSH command.

B$ while true; do ssh -R ... user@host; done

1
  • good to use ssh -N with -L or -R 'cos don't need a shell when doing -L or -R.
    – barlop
    Commented Jun 17, 2022 at 2:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .