I have my nextcloud server (vers. 20) on a local PC, I would like to configure my client so that when I’m at home it syncs locally (with an address like 192.168.1.99), while when I’m not at home it uses a different IP/host as the sync address (like myip.com:9999), basically if it doesn’t find the server on the local IP, it tries on the remote one, is it possible to do this?
No, that’s not possible. You would have to reconfigure your client every time you leave your home and then again when you return.
It’s also bad from a security perspective, because there’s no way to obtain a valid certificate for an IP address (unless you’re the owner of a fixed public IP range or have a “Letter of Authorization” from your ISP for your public IP address), which is less than ideal if your Nextcloud is accessible from the internet. And no, using a port other than 443 does not make it any more secure. That open port can be discovered within seconds using tools like Nmap.
There are several ways to tackle this problem. Here are three options:
Buy a domain name and use something like cloud.yourdomain.tld for internal and external access, with proper TLS certificates (e.g., from Let’s Encrypt).
Use a traditional VPN to connect to your home network. That way, you could still use the local IP externally. Although this is still suboptimal, in my opinion, as Nextcloud really works best with a domain name and proper TLS certificates.
Maybe there is anorther option, that will work if your local Router/Firewall/DNS supports it and you do not use different ports for external/internal access (eg 9999 / 443). That means internal and external ports need to be 443.
You may set a Alias Name in your local DNS that will redirect cloud.yourdomain.tld to the local private IP of your Nextcloud Server. If your router does not support that you may setup a local KEA-DNS and make the KEA to your default DNS in your home-net.
The DNS of the router need to be turned off then and the DHCP-Server of the route must submit the IP of the KEA as new local DNS to all clients in your LAN.
If not, then I absolutely wouldn’t recommend doing anything that involves exposing your server to the internet until you’ve updated it to a supported version!
Thanks for the reply, the reason why I would like to have local access is to speed up the sync at least when I’m at home, without having to go through the internet (my connection is not very fast), so I might consider using a VPN, honestly I don’t think having a public/host IP improves security
You’re right, and it’s not a typo, but I haven’t been able to upgrade yet. I have about 400GB of data, so I don’t want to have to reload everything. If you can suggest a guide on how to proceed, I’d be grateful.
You can still have that, even with a domain name, you just need to setup proper split brain DNS, as @adelaar explained.
But first, please update your server! And keep it up to date. Otherwise, you really shouldn’t expose it to the internet.
And even if you’re going to use a VPN, please keep all your software reasonably up to date. Exposing it to the internet is not the only attack vector, and an environment is always only as secure as its weakest point (which is usually the user, but that’s a different topic).