Nextcloud impossible to reach through DDNS in LAN

Nextcloud version (eg, 20.0.5): 22.2.0
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04.3 LTS

Hello,

I’m using the Snap version of Nextcloud in Ubuntu.
My host is reachable via a DDNS.
I’ve used Letsencrypt to install a SSL certificate to enable HTTPS for the DDNS domain.

Nextcloud can be used perfectly from the Android app and browser when reaching it outside the LAN (from the internet). However within the LAN, using the DDNS domain just causes a big time for loading it and in most of the attempts the browser will give a timeout error.

I know I can use the IP address instead, but then on the android app I would have to switch the hostname everytime I change from home to outside home and viceversa.

Also the SSL certificate is invalid within the LAN because the machine has a different hostname than the DDNS domain. And I can’t set the same DDNS domain as a hostname because the hostname can’t contain dots.

Can anyone help me with this? I’m pretty sure this is a trivial problem.

This comes down to your router.

The simplest way to get where you are going is to set up a hostname on the router itself with the DNS name and local IP address of the NC host. The router will prioritize a hardcoded local hostname over DNS if your local clients make their DNS requests to the router IP.

The other option is to muck around in the firewall/routing configuration on your router to get it to feed the packets back properly to the NC host. Depending on your router, this may or may not be possible, i.e., it is possible on OpenWRT. It may not be possible on some junk commercial firmware.

The problem with the second option, if it works, is if your WAN connection goes down, you’ll lose your local NC.

The problem with the first option, is if your clients do NOT use your router as DNS server, it won’t work at all.

Doing both would probably be the best option, since for clients that use the router as DNS, it will always work, and for clients that do NOT, it will work when the WAN is operational.

Now want to get into more fun ideas? Use IPv6 instead of IPv4, then your global DNS will be set to the IP address of the NC host AND NOT your router.

In addition to what Larry said, I wanted to mention that many consumer routers have a feature called NAT loopback, NAT reflection or Hairpin NAT. This would be the easiest solution und should work with all devices in your local network. If your router dosn’t support that and also dosn’t support any of the things Larry mentioned, you could setup your own local DNS server. The easiest way to do that is probably Pi-hole, which also supports “Host-overrides”. That’s the thing Larry mentioned in the first paragraph of his post.