CH 42 / 50Chapter 8: Hands-On

Exposing a Synology NAS with Cloudflare Tunnel

On this page21 items

On the previous page, we moved a server that was already on the internet behind Cloudflare. This time we go the other way: we’ll publish a device at home that isn’t exposed to the internet at all, without opening a single port.

Our subject is a Synology NAS. The mechanism was explained in Cloudflare Tunnel in Chapter 3; here we’ll actually do the work and get to the point where you can access your home NAS on your own domain.

It doesn’t have to be a NAS. A Raspberry Pi, a home server, an internal business system, an app under development — anything running locally that speaks HTTP can use the same steps.

What you’ll learn on this page#

  • How to actually create a Cloudflare Tunnel (from the dashboard all the way through)
  • How to run cloudflared on a Synology NAS
  • How to configure a public hostname, and how to avoid the NAS’s HTTPS certificate error
  • Limits you must know before publishing (the 100 MB upload cap)
  • What to do after publishing, up to adding authentication

Before you start#

You only need three things.

  • A domain managed on Cloudflare (with steps 1–3 from the previous page done)
  • A Synology NAS (DSM 7.2 or later, with Container Manager available)
  • Internet access from the NAS (if you’re using it normally, you’re fine)

You won’t touch your router settings at all. No port forwarding, no static IP, no DDNS. That’s the best thing about Tunnel.

Note that once you publish your NAS this way, anyone in the world who knows the URL can reach it. Adding authentication is covered at the end of this page and on the next page. Pay attention to the order of the steps so you don’t leave a NAS holding real data exposed without protection while you work.

Overview of publishing with Tunnel

Step 1: Create a tunnel#

Log in to the Cloudflare dashboard, open Networking → Tunnels (it used to be under Zero Trust → Access → Tunnels), and select Create Tunnel.

When asked for the connector type, choose Cloudflared and give the tunnel a name. Pick something you’ll recognize later that identifies the device, such as home-nas.

When you save, installation commands are displayed. You can switch between OSes and package formats; select the Docker tab. The command looks something like this:

text1 lines
docker run cloudflare/cloudflared:latest tunnel --no-autoupdate run --token eyJhIjoi...(long string)

That long string starting with eyJ is the tunnel token. This token is, in itself, the authority to run that tunnel. If someone else gets it, they can connect their own server under your domain. Never post a screenshot of it on a blog or paste it into a chat.

Step 2: Run cloudflared on the NAS#

Now run cloudflared, with the token, inside the NAS. We’ll use Synology’s Container Manager.

Download the image#

  1. In DSM, open Container Manager
  2. In Registry in the left menu, search for cloudflared, select cloudflare/cloudflared, and download it (tag latest)

Create the container#

  1. In the left menu, go to Container → Create
  2. Choose cloudflare/cloudflared:latest as the image
  3. Network: bridge is fine as is. However, for reasons explained below, using host network sometimes works more smoothly (see below)
  4. Check Enable auto-restart (so it reconnects automatically after the NAS restarts)
  5. In the Command field, enter the following
text1 lines
tunnel --no-autoupdate run --token eyJhIjoi...(the token you copied)
  1. Create and start it

No port settings needed#

This is where people often get confused. Container Manager shows a screen for mapping “local ports” to “container ports,” but with cloudflared you don’t need to set anything. That’s because cloudflared doesn’t accept incoming connections. Its traffic only goes out from the NAS, so there’s no port to open.

This is what “the direction of communication is reversed,” explained in Chapter 3, looks like in practice.

Check that it’s connected#

Back in the Cloudflare dashboard, the tunnel’s status should now be Healthy. If it’s still Down, check on the NAS that the container is running and that the token was pasted correctly. If there’s an error in the Container Manager log, it will tell you the cause.

Step 3: Configure the service to publish#

The tunnel is connected, but at this point nothing is published yet. That’s because you haven’t decided “when a request comes to which URL, where in the NAS to send it.”

On the tunnel’s detail screen, select Add route (formerly the Public Hostname tab) and add a Published application.

FieldExampleDescription
SubdomainnasThe subdomain you want to use
Domainexample.comA domain managed on Cloudflare
PathBlankUse this to publish only a specific path
TypeHTTPThe protocol the NAS speaks
URL192.168.1.10:5000The NAS’s local IP and DSM’s port

When you save, a DNS record is created automatically. On the DNS screen, you should see a CNAME record for nas added with the orange cloud. You don’t need to register an IP address yourself (which is a big advantage, since home connections often can’t have a fixed global IP anyway).

Wait a few dozen seconds, then open https://nas.example.com. If the DSM login screen appears, you’ve succeeded.

Why specify HTTP instead of HTTPS#

You may be tempted to put https://192.168.1.10:5001 in the URL field, but in many cases this fails. DSM’s HTTPS (port 5001) often uses a self-signed certificate, and cloudflared can’t verify that certificate, so it errors out.

There are two ways to deal with this.

  • Set Type to HTTP and URL to 192.168.1.10:5000 (recommended). The connection between the NAS and cloudflared is inside your home LAN, so leaving it unencrypted does little real harm, and from visitors to Cloudflare it’s HTTPS as a matter of course
  • If you really want HTTPS, enable No TLS Verify in the additional settings

When the local IP doesn’t work#

Sometimes the setup is such that the container can’t reach 192.168.1.10. In that case, try one of the following.

  • Set the container’s network to host network and use localhost:5000 as the URL
  • Depending on your Container Manager environment, host.docker.internal:5000 may work

Step 4: Limits to know before publishing#

This is where you get excited that it’s connected, but when publishing a NAS, there are limits you must know about.

What passes through Tunnel and what doesn't

Uploads are limited to 100 MB (Free and Pro plans)#

There’s a maximum body size for a single request passing through Cloudflare’s proxy.

PlanLimit per request
Free100 MB
Pro100 MB
Business200 MB
Enterprise500 MB (default; can be raised)

In other words, on the Free plan you can’t upload files larger than 100 MB to your NAS. If “photos upload fine but videos always fail,” this is almost certainly the cause. There’s no limit on downloads, so viewing and downloading are fine.

As a workaround, uploads will go through if the sending side supports chunked uploads. Alternatively, you can route only large transfers through a private network connection via WARP (see below).

Mind the terms for video streaming#

Cloudflare’s terms of service restrict serving large amounts of video and non-HTML content through its proxy. Routinely using a NAS’s media server feature through Tunnel isn’t an intended use. It’s unlikely to be a problem if you occasionally watch your own videos, but understand that it isn’t suited to “turning your home NAS into a video streaming platform”.

Responses taking over 125 seconds are cut off#

If you wait on a long-running process on the NAS side, such as creating a large archive, Cloudflare gives up waiting and returns a 524 error.

File-sharing protocols like SMB and AFP don’t pass through#

Public hostnames can only be set up for HTTP, HTTPS, and similar protocols. Mounting the NAS as a network drive from Finder or File Explorer isn’t possible with this method. If you want to do that, install the WARP client on your device and use a setup where it reaches the NAS’s IP address directly as a private network (register an IP range such as 192.168.1.0/24 as the tunnel’s Private network).

Step 5: Add authentication#

At this point, https://nas.example.com is open to anyone in the world. The DSM login screen protects it, but the login screen itself is exposed to brute-force attacks. To make the most of having stopped port forwarding, you need one more layer of defense.

The strongest measure is to put authentication in front of the login screen with Cloudflare Access. People who don’t pass authentication won’t even see the DSM login screen. From an attacker’s point of view, they can’t even tell there’s a NAS there.

That’s the topic of the next page. Once you’ve created the tunnel, go straight on to setting up authentication.

If you need minimal protection in a hurry, you can also limit login attempts with Rate Limiting, or block access from countries other than Japan with a custom WAF rule.

Points for beginners to watch out for#

  • Never share the token: The tunnel token is a key that can hijack that tunnel. If you think it has leaked, delete the tunnel in the dashboard and create a new one
  • Fix the NAS’s IP address: If the NAS’s local IP changes via DHCP, the tunnel’s destination gets lost. Set up a DHCP reservation on your router or a static IP on the NAS first
  • Remove DDNS and port forwarding, which you no longer need: Once Tunnel is working, be sure to delete any port forwarding you set up before. If it remains, an old hole stays open right next to your nice, secure route
  • What --no-autoupdate means: It prevents cloudflared from updating itself inside the container. Updates are done by pulling the image again. Re-pull latest periodically
  • Prepare for NAS restarts: If you don’t enable “auto-restart” in Container Manager, the tunnel stays disconnected after the NAS restarts
  • One tunnel can publish multiple services: By adding public hostnames, you can route nas.example.com to DSM, photo.example.com to Synology Photos, app.example.com to your own app, and so on. Creating one tunnel per device keeps things tidy
  • Always verify authentication before going live: Open it in a private window and confirm that an authentication screen appears instead of the login screen

Related services#

Summary#

  • With Tunnel, you can publish a NAS without router port forwarding, a static IP, or DDNS
  • The process has three stages: “create a tunnel in the dashboard → run cloudflared on the NAS → configure a public hostname”
  • In Container Manager, no port settings are needed, because cloudflared doesn’t accept incoming connections
  • The reliable target URL is HTTP + local IP + port 5000. This avoids tripping over DSM’s self-signed certificate
  • The DNS record is created automatically. You don’t need to register your home’s global IP
  • On the Free and Pro plans, a single upload is limited to 100 MB. Not suited to routine video streaming or SMB mounts
  • After creating the tunnel, always go on to add authentication with Access. That’s what completes the point of giving up port forwarding

The long-standing common practice of port forwarding becomes entirely unnecessary — once you actually run Tunnel, you should feel that Zero Trust isn’t just an abstract idea.

On the next page, we’ll put Access in front of the NAS we just published, so that only people who pass authentication can reach the login screen.

Read next#