NeuroAgent

Setting Up Nextcloud Mobile Sync: Split DNS

Complete guide to configuring split DNS for Nextcloud. Learn how to ensure fast synchronization in your local network and remote access without file duplication.

Question

How to properly configure Nextcloud mobile synchronization both externally and from within the local network?

I’ve installed Nextcloud on a TrueNAS server, have a public IP with forwarded ports and a purchased domain. Browser access works correctly from any location, but access from the home network provides significantly higher speed.

When setting up automatic synchronization through the Nextcloud app, I configured two servers (local and external) for the same user account, but during synchronization, files are being duplicated on the server.

I would like to have the ability to automatically back up data when away from home, while still getting high synchronization speeds within the home network without creating duplicate file copies.

Question: Is it possible that I misconfigured Nextcloud itself? Or do I need to configure redirection of requests from the public IP within the home network so they don’t route through external servers but stay within the local network? If so, at what level should this redirection be configured - in the phone app or in the router?

NeuroAgent

Setting up Proper Nextcloud Mobile Synchronization from Both Outside and Inside Your Local Network Without File Duplication

To properly configure Nextcloud mobile synchronization from both outside and inside your local network without duplicating files, you need to implement split DNS, which will automatically direct requests based on your location. This will allow your Nextcloud domain to resolve to your local IP when on your home network and to your public IP when connecting from outside, eliminating the need for dual server configuration and preventing file duplication.

Table of Contents


Setting up Split DNS for Local and External Access

Split DNS, also known as split-horizon DNS, is the optimal solution for your situation. This method allows the same domain name to resolve to different IP addresses depending on where the client is located.

How it works:

  • Inside your local network, the domain yourdomain.com resolves to the local IP address of your server (e.g., 192.168.1.100)
  • Outside the local network, the same domain resolves to your public IP address

Setup steps:

  1. Configure local DNS:

    • In your router or DNS server settings (e.g., Pi-hole, dnsmasq), add an A record for your domain pointing to the local IP of your Nextcloud server
    • If using NextCloudPi, activate dnsmasq and set your home devices to use it as the primary DNS server
  2. External DNS configuration:

    • Ensure your public DNS (typically provided by your hosting or domain registrar) has an A record pointing to your public IP

Important: Split DNS does not require changes to the Nextcloud server configuration itself - all the magic happens at the DNS level.


Router Configuration for Internal Routing

If split DNS doesn’t work for some reason, you can configure redirection at the router level. This is particularly useful if your router supports NAT reflection.

Configuration options:

  1. NAT Reflection (if supported by your router):

    • In your router settings, find the “NAT Reflection” or “Hairpin NAT” section
    • Enable this option for the ports used by Nextcloud (typically 80 for HTTP and 443 for HTTPS)
    • This will allow devices on the local network to access the server through the public IP without going out to the internet
  2. Routing configuration:

    • Create a routing rule that will redirect traffic from the public IP to the local IP provided the source is in the same subnet
    • This is a more advanced method requiring understanding of networking concepts

TrueNAS Router Configuration:
If your TrueNAS server also functions as a router, you may need to configure firewall rules and port forwarding for local access.


Nextcloud App Configuration for Automatic Network Selection

The Nextcloud mobile app itself doesn’t have a built-in function for automatically switching between local and external servers, but proper split DNS configuration makes this unnecessary.

Correct app configuration:

  • Configure only one server in the Nextcloud app - your domain (yourdomain.com)
  • Thanks to split DNS, the app will automatically connect to the local server when at home and to the external server when connecting from outside
  • Never configure two separate servers for one account - this will lead to file duplication

Important: As noted in the Nextcloud community, attempting to use two servers for one account will inevitably lead to synchronization issues and data duplication.


Preventing File Duplication

The file duplication problem occurs precisely due to incorrect configuration of two servers. Here’s how to fix it:

Cause of duplication:

  • When configuring two servers (local and external), the Nextcloud app treats them as two separate storage locations
  • Files synchronized from the local server are not visible on the external server and vice versa
  • When switching between networks, the app may think these are new files and start downloading them

Solution:

  1. Remove the second server from your Nextcloud app settings
  2. Configure only one server - your domain
  3. Ensure split DNS is properly configured

Additional precautions:

  • Regularly check your DNS settings using tools like nslookup or dig
  • Test connectivity from both within your local network and from outside
  • Monitor synchronization logs for errors

Alternative Methods and Best Practices

If split DNS isn’t suitable for your configuration, there are alternative methods:

1. VPN Connection:

  • Set up a VPN server for access to your home network
  • After connecting to the VPN, the Nextcloud app will automatically see the local server
  • This method provides security but may add some latency

2. Local Path Configuration:

  • As suggested by one user on Reddit, you could add functionality to the app to try the local IP before the external domain

3. Using Automation Scripts:

  • Create a script that will automatically change DNS settings on your device when connecting to home Wi-Fi
  • This method is more complex to set up but may be useful for advanced users

Best Practice:
As experts in the Nextcloud community note, the optimal solution is always to use split DNS because it:

  • Doesn’t require client-side changes
  • Works automatically
  • Provides maximum performance in both situations
  • Prevents all data duplication issues

Conclusion

  1. Primary solution - Set up split DNS so your Nextcloud domain automatically resolves to your local IP when on your home network and to your public IP when connecting from outside.

  2. Never use two servers for one Nextcloud account - this will inevitably lead to file duplication and synchronization problems.

  3. Configure your router to support NAT reflection or similar features if split DNS doesn’t work for some reason.

  4. In the Nextcloud app, configure only one server - your domain. Thanks to proper DNS configuration, the app will automatically choose the optimal connection path.

  5. Test your configuration from different locations to ensure synchronization works correctly both locally and externally without data duplication.

Proper split DNS configuration will solve all your performance and file duplication issues, providing automatic selection of the optimal connection path without the need for manual intervention or complex app configuration.

Sources

  1. Setting up Local and Remote Synchronization - Nextcloud Community
  2. Using LAN Instance at Home and Cloud Instance Away from Home - Reddit
  3. Way to Make Nextcloud Android App Use Local Network - Reddit
  4. How to Access Nextcloud via Domain Name on Local Network - Reddit
  5. Deduplication Over the Network for Client Sync - Nextcloud Community