28 January 2025

Running Syncthing on Flint OpenWRT Router

My GL.inet GL-ATX1800 (Flint) router is currently running Firmware version 4.6.8 which equates to a somewhat modified OpenWRT 21.02.

I recently heard about Syncthing from the Security Now podcast, and decided to setup it up on my Ubuntu laptop and router as a kind of poor man's backup.

Install Syncthing on the Router

From the Flint web UI, if you goto Applications -> Plug-ins and then search for Syncthing, version 1.18.2.1 is available for install. This version is a little bit old, but I used it rather than installing or building the latest version.

After installing, Syncthing does not run automatically, so you have to ssh onto the router to make a few changes.

Also note there is very limit free storage on the Flint, so you will need to add a USB disk - I have a 256GB Nvme drive in a USB enclosure for this purpose.

Getting Syncthing to Run

Syncthing is installed as a service, so you can start it with:

service syncthing start

However it would not start from that simple command. Searching the filesystem for syncthing references yielded:

/etc/config/syncthing
/etc/init.d/syncthing
/etc/syncthing
/lib/upgrade/keep.d/syncthing
/overlay/upper/etc/init.d/syncthing
/overlay/upper/etc/syncthing
/overlay/upper/etc/config/syncthing
/overlay/upper/lib/upgrade/keep.d/syncthing
/overlay/upper/usr/bin/syncthing
/overlay/upper/root/.config/syncthing
/usr/bin/syncthing

Digging further, the /etc/config/syncthing file contained:

config syncthing 'syncthing'
        option enabled '1'

        option gui_address 'http://192.168.8.1:8384'

        # Use internal flash for evaluation purpouses. Use external stor
        #   for production.
        # This filesystem must either support ownership/attributes or
        #   be readable/writable by the user specified in
        #   'option user'.
        # Consult syslog if things go wrong.
        option home '/tmp/mountd/disk1_part1/syncthing'

        # Changes to "niceness"/macprocs are not picked up by "reload_co
        #   nor by "restart": the service has to be stopped/started
        #   for those to take effect
        option nice '19'

        # 0 to match the number of CPUs (default)
        # >0 to explicitly specify concurrency
        option macprocs '0'

        # Running as 'root' is possible, but not recommended
        option user 'syncthing'

The first line option enabled '1' defaulted to '0', preventing the service from starting, so changing it to '1' got it going. I also modified the gui_address to the LAN IP of the router so I can access the UI easily.

Next I changed to the option option home '/tmp/mountd/disk1_part1/syncthing' to a folder on the mounted USB disk, and also set the owner:group of that folder to Syncthing, as the process runs as that user by default. This folder is where Syncthing will store its indexes, keys etc, so it is best on external storage than the routers internal flash storage. After starting the service, Syncthing created its required files in that location:

ls -al /tmp/mountd/disk1_part1/syncthing
drwx------    4 syncthin syncthin      4096 Jan 25 23:16 .
drwxr-xr-x    7 root     root          4096 Jan 24 22:34 ..
-rw-r--r--    1 syncthin syncthin       794 Jan 24 22:38 cert.pem
-rw-------    1 syncthin syncthin      9879 Jan 25 23:16 config.xml
-rw-------    1 syncthin syncthin      7273 Jan 24 22:38 config.xml.v0
-rw-------    1 syncthin syncthin        66 Jan 25 10:51 csrftokens.txt
-rw-r--r--    1 syncthin syncthin       794 Jan 24 22:38 https-cert.pem
-rw-------    1 syncthin syncthin       288 Jan 24 22:38 https-key.pem
drwxr-xr-x    2 syncthin syncthin      4096 Jan 26 10:45 index-v0.14.0.db
-rw-------    1 syncthin syncthin       288 Jan 24 22:38 key.pem

The GUI can also be accessed at http://192.168.8.1:8384 with no password by default.

Default Folder Location

By default Syncthing wants to create a default synced folder called Sync. In my setup, it was unable to create it, and was attempting to create it at /Sync. To fix that, edit the config.xml file in home folder and locate the folder definition at the top of the file. I modified it to create the folder in a synced_data folder under the home directory:

configuration version="35">
    <folder id="default" label="Default Folder" path="/tmp/mountd/disk1_part1/syncthing/synced_data/Sync" type="sen...

Default Location For Remote Folders

I encoutered another problem when I setup Syncthing on my laptop, and shared a folder with the router. The router was not able to create the folder, as it did not know where store it. To fix that, on the router's Syncthing GUI, navigate to Actions in the top right, then Settings and under the first tab, General, click Edit Folder Defaults. Under Folder Path add the root folder you would like remote shared to be created under, which is /tmp/mountd/disk1_part1/syncthing/synced_data in my case.

External Discovery, NAT, Port Forwarding

When on my LAN, Syncthing connects perfectly. If I leave it with the default settings, when I move the laptop off the LAN (eg a mobile hotspot), Syncthing still manages to connect, but the connection is via a relay server. If I disable relay servers, it can no longer connect my router and laptop if they are not both on the LAN. This makes sense - my ISP is behind CGNAT and my laptop has no firewall ports opened.

I have Tailscale configured, and the router node "advertises routes" of the local LAN to the Tailnet. When I connect to the Tailnet Syncthing can connect to the LAN address 192.168.8.1.

What I am not sure about, is what would happen in such a setup if I had multiple hosts on the Tailnet outside the LAN that I want to talk to each other, but only when both are on the Tailnet. As it is working well enough for what I need now, I will leave that as a task for another day!

blog comments powered by Disqus