At 2:15 AM, my primary Synology NAS froze hard enough to require a physical reboot. My first suspect was a heavy Docker stack or a runaway database query.
The real cause was much simpler, and much more embarrassing: port 5001 was still exposed to the public Internet.
Over a few hours, a distributed botnet threw roughly 5,700 failed login requests (SYNO.API.Auth) from more than 900 unique IP addresses, peaking above 1,100 requests per hour. Because each IP only tried a handful of passwords, Synology’s built-in Auto Block barely slowed it down. Worse, the flood hit right in the middle of my nightly Hyper Backup disk I/O window. Concurrent writes to pam_syno_ipblocklist stalled on lock contention, leaving ~1,900 SYNO.API.Auth CGI processes piled up in memory.
Each CGI process only used around 25 MiB of RAM, so when physical RAM and swap finally hit 100%, the Linux OOM killer did what its scoring algorithm told it to do: it ignored the 1,900 tiny auth workers and killed large, healthy containers (mariadbd, web servers, etc.) instead. Within minutes the box was wedged.
Closing DSM port 5001 and SSH from the WAN sounds like a five-minute job. In practice, on a NAS that hosts public web apps, syncs Synology Drive to desktop and mobile devices, runs Docker containers in a DMZ, and receives offsite Active Backup for Business (ABB) jobs from another Synology NAS, several non-obvious traps show up immediately.
Here is the exact hardening blueprint I ended up with, the traps that nearly bit me, and a 4-line /etc/hosts + Tailscale TUN trick that moves remote Active Backup for Business traffic off the public Internet without disconnecting the agent or breaking TLS certificates.
1. The Target Network Architecture
Before touching any firewall rule, I listed every traffic flow hitting the primary NAS (primary-nas, sitting in a router DMZ at 192.168.1.25 with Tailscale IP 100.64.10.10):
- Must stay public (WAN):
80, 443/TCP: Public reverse-proxied apps (cloud.example.com,photos.example.com,drive.example.com, etc.)6690/TCP: Synology Drive desktop sync clients1194, 500, 1701, 4500/UDP(+ ESP/AH): Backup OpenVPN / L2TP VPN server41641/UDP: Tailscale WireGuard direct P2P (so nodes don’t fall back to slow DERP relays)- Any explicitly public service port (e.g., a public Mumble voice server or P2P node)
- Must be private (VPN / LAN only):
- SSH (
2222/TCP): Tailscale (100.64.0.0/10) and OpenVPN (10.8.0.0/24) only — blocked even on raw LAN. - DSM WebUI & API (
5000, 5001/TCP): LAN, Tailscale, OpenVPN, plus a single whitelisted external uptime-monitor IP (198.51.100.25) if you monitor DSM from an external status page. - Active Backup for Business (
5510/TCP): Tailscale and LAN only. - Admin Reverse Proxies (
nas.example.com,portainer.example.com, etc.): LAN, Tailscale, OpenVPN only. - Everything else in the DMZ (FTP
:21, SMB:445, raw Docker host ports:8082,:9000, etc.): Dropped on WAN.
- SSH (

2. Trap #1: Closing :5001 in the Firewall While Leaving It Open on :443
Right after blocking 5000, 5001/TCP in the DSM Firewall, I audited /usr/syno/etc/www/ReverseProxy.json and caught a nasty blind spot:
nas.example.com:443 -> https://localhost:5001 (ACL: none)
portainer.example.com:443 -> http://localhost:9000 (ACL: none)
Because NGINX terminates TLS on :443 (which is open to the Internet) and forwards the request to localhost:5001, traffic hits DSM over loopback 127.0.0.1 and completely bypasses the DSM Firewall. Anyone hitting https://nas.example.com/webapi/auth.cgi could still brute-force DSM right through port 443.
Fix: Attach a DSM Access Control Profile to Every Admin Reverse Proxy
In Control Panel → Login Portal → Advanced → Access Control Profile, create a profile (for example Admin Private) with:
- Allow:
127.0.0.1 - Allow:
192.168.1.0/24(and any secondary local subnets, e.g.192.168.3.0/24) - Allow:
100.64.0.0/10(Tailscale) - Allow:
10.8.0.0/24(OpenVPN) - Allow:
198.51.100.25(only if an external uptime monitor checksportainer.example.comornas.example.com) - Deny:
All(must be the final rule)
Assign that profile to nas.example.com, portainer.example.com, and any other internal admin UI exposed through Reverse Proxy (code-server, browser containers, internal analytics). Verify from an external IP (like a phone on cellular data):
curl -s -o /dev/null -w "%{http_code}\n" https://nas.example.com
# Expected from WAN: 403
3. Trap #2: Synology Drive Desktop vs. Mobile
Closing :5001 has zero impact on Synology Drive desktop clients (Windows, macOS, Linux) because they sync over 6690/TCP.
The Synology Drive mobile app, however, connects over HTTPS — and if you never gave Synology Drive its own subdomain, mobile users were connecting to nas.example.com:5001, which now times out.
Fix: Dedicated Subdomain on :443
- Create a DNS record:
drive.example.com→CNAME→nas.example.com. - In DSM, go to Control Panel → Login Portal → Applications → Synology Drive → Edit and set Customized domain to
drive.example.com. - Under Control Panel → Security → Certificate → Settings, make sure
SynologyDrive - drive.example.comuses your wildcard certificate (*.example.com).
curl -sI https://drive.example.com | head -n 5
# Should return HTTP/1.1 200 OK with Synology Drive headers, NOT a JS redirect to :5001
Now mobile Drive users sign into drive.example.com on standard :443, while DSM admin (:5001) stays closed to the Internet.
4. The Main Trick: Moving Remote Active Backup for Business to Tailscale Without Relinking or Breaking SSL
This was the trickiest part of the migration. A remote Synology NAS (remote-nas, behind a dynamic residential ISP IP) backs up every night to my primary NAS using Active Backup for Business Agent (DSM).
Why you can’t just put an HTTP reverse proxy in front of ABB
Active Backup for Business Agent uses two ports on the same server address:
5001/TCP(HTTPS): Initial authentication, pairing, and re-trusting the TLS certificate when Let’s Encrypt renews it every ~60 days.5510/TCP(Proprietary binary TLS, not HTTP): Persistent agent connection and actual backup transfer.
Because :5510 is not HTTP, DSM’s NGINX Reverse Proxy (:443) cannot proxy it. And the « Proxy Settings » popup inside the ABB Agent UI is for a client-side corporate HTTP forward proxy (like Squid on :8080), not a server-side reverse proxy.
Why simply installing Tailscale on the remote NAS isn’t enough
- The DSM 7 Tailscale Outbound Trap: On DSM 7, the Tailscale package runs in
userspace-networkingmode by default. Your primary NAS can pingremote-nas(100.64.10.20), so Tailscale looks healthy in the admin console — but outbound connections initiated by local DSM packages onremote-nas(like the ABB Agent) to100.64.10.10fail unless Kernel TUN is configured. - The ABB Agent UI locks the server field: While connected to
nas.example.com, you cannot edit the destination host in-place without disconnecting and relinking. And switching the host to a raw Tailscale IP (100.64.10.10) breaks the TLS certificate hostname match for*.example.com.
The 4-Line Zero-Relink Solution (/etc/hosts + Tailscale TUN)
Instead of disconnecting the ABB Agent or changing its destination domain, keep nas.example.com in ABB and override how remote-nas resolves it locally.
On remote-nas, open Control Panel → Task Scheduler → Create → Triggered Task → User-defined script (Event: Boot-up, User: root):
/var/packages/Tailscale/target/bin/tailscale configure-host
/usr/syno/bin/synosystemctl restart pkgctl-Tailscale.service
grep -q "100.64.10.10 nas.example.com" /etc/hosts || echo "100.64.10.10 nas.example.com" >> /etc/hosts
/usr/syno/bin/synosystemctl restart pkgctl-ActiveBackup-DSM.service
Save the task and click Run once immediately (check Action → View Result for exit code 0).
Why this works so cleanly:
- No disconnect or relink in Active Backup for Business — existing tasks and backup version history stay untouched.
- Exact TLS certificate match: the agent still connects to
nas.example.com, matching your*.example.comwildcard certificate. - Both
:5001and:5510move onto Tailscale automatically:tailscale configure-hostcreates the kerneltailscale0interface so local DSM services can initiate outbound connections over Tailscale, and/etc/hostsforcesnas.example.comto100.64.10.10. - Survives reboots: because it runs as a Boot-up triggered task, DSM updates or reboots won’t break the tunnel or the
/etc/hostsentry.
Verify the Switch on the Primary NAS
SSH into your primary NAS and inspect the live sockets on port 5510:
sudo netstat -tnp | grep 5510
# Before (public ISP IP):
# tcp 0 0 192.168.1.25:5510 198.51.100.42:33966 ESTABLISHED 12982/abk-agent-ser
# After (Tailscale overlay):
# tcp 0 0 100.64.10.10:5510 100.64.10.20:51274 ESTABLISHED 12982/abk-agent-ser
# tcp 0 0 100.64.10.10:5510 100.64.10.20:51267 ESTABLISHED 12982/abk-agent-ser
Once confirmed, you can block 5510/TCP from the WAN entirely. (If your primary NAS also pushes outbound bare-metal ABB backups to another remote NAS on :5510, those outbound connections remain unaffected thanks to RELATED,ESTABLISHED state tracking.)
5. Switching a DMZ Synology Firewall to Default-Deny (Without Breaking Docker)
If your NAS sits in a router DMZ and DSM Firewall is set to « If no rules are matched: Allow », blocking :5001 and :2222 still leaves a wide surface open on 0.0.0.0: FTP (:21), SMB (:445), Portainer (:9000), and every published Docker container port (which bypasses NGINX SSL and ACLs completely).
Flipping to Default-Deny closes all of those in one move, provided you avoid four Synology-specific gotchas:
- Allow Docker bridge subnets (
172.16.0.0/12AND192.168.0.0/16): Synology applies global firewall rules to bothINPUT_FIREWALLandFORWARD_FIREWALL. Checkip -4 addr showon your NAS — Docker stacks often allocate bridges in both172.17–172.31.x.xand192.168.16–159.x. If you omit them, container-to-container and container-to-Internet traffic silently dies. - Put SSH rules above LAN/Docker catch-alls: If you want SSH restricted strictly to Tailscale and OpenVPN (blocked even on LAN),
Allow SSH (Tailscale/OpenVPN)→Deny SSH (All)must sit at the very top of the rule list, beforeAllow All from 192.168.0.0/16. - Allow Tailscale UDP
41641publicly: Without41641/UDPopen on WAN, Tailscale stays connected through DERP relays, which works but throttles backup throughput. - Allow
169.254.0.0/16if you use QuickConnect: Synology’ssynorelayddaemon creates atun1000interface in169.254.x.x.
Final Ordered DSM Firewall Rule Table
| Order | Rule | Ports / Protocol | Source | Action |
|---|---|---|---|---|
| 1 | SSH from Tailscale | 2222, 22/TCP |
100.64.0.0/10 |
ALLOW |
| 2 | SSH from OpenVPN | 2222, 22/TCP |
10.8.0.0/24 |
ALLOW |
| 3 | Deny SSH from All | 2222, 22/TCP |
All (IPv4 & IPv6) | DENY |
| 4 | Full trust: Tailscale | All | 100.64.0.0/10 |
ALLOW |
| 5 | Full trust: OpenVPN | All | 10.8.0.0/24 |
ALLOW |
| 6 | Full trust: LAN & Docker 192.168 |
All | 192.168.0.0/16 |
ALLOW |
| 7 | Full trust: Docker 172.16 bridges |
All | 172.16.0.0/12 |
ALLOW |
| 8 | QuickConnect tun1000 (if used) |
All | 169.254.0.0/16 |
ALLOW |
| 9 | External Uptime Monitor (optional) | 5000, 5001/TCP |
198.51.100.25 |
ALLOW |
| 10 | Public Reverse Proxy & Drive Web/Mobile | 80, 443/TCP |
All (IPv4 & IPv6) | ALLOW |
| 11 | Synology Drive Desktop Sync | 6690/TCP |
All (IPv4 & IPv6) | ALLOW |
| 12 | VPN Server (OpenVPN / L2TP / IPSec) | 1194, 1701, 4500, 500/UDP, ESP, AH |
All (IPv4 & IPv6) | ALLOW |
| 13 | Tailscale WireGuard Direct | 41641/UDP |
All (IPv4 & IPv6) | ALLOW |
| 14 | Any explicitly public service (e.g. Mumble) | Service ports | All (IPv4 & IPv6) | ALLOW |
| 15 | Catch-all DMZ Drop | All | All (IPv4 & IPv6) | DENY |
rsync over SSH to your NAS, add a two-line automatic fallback so it switches to Tailscale when LAN SSH is blocked:
TARGET_NAS="192.168.1.25"
if ! nc -z -w 2 "${TARGET_NAS}" 2222 2>/dev/null; then
TARGET_NAS="100.64.10.10"
fi
6. Post-Change Verification Checklist
Before closing your active Tailscale SSH session, verify every path:
- Inspect the compiled
iptablesrules and live packet counters:Check live firewall rules and drop counters bashsudo iptables -L INPUT_FIREWALL -nv --line-numbers sudo ip6tables -L INPUT_FIREWALL -nv --line-numbersWithin minutes of enabling the final
DROP allrule in a DMZ, you will see the drop counter climb rapidly from background Internet scanners — while rules for443,6690,41641, and your VPN subnets stay cleanly matched. - Confirm SSH is open on Tailscale and blocked on LAN:
Verify SSH isolation bash
nc -z -w 2 100.64.10.10 2222 && echo "Tailscale SSH OK" nc -z -w 2 192.168.1.25 2222 || echo "LAN SSH blocked as expected" - Confirm Reverse Proxy ACLs return
403from outside (testhttps://nas.example.comandhttps://portainer.example.comon mobile data without VPN). - Confirm
https://drive.example.comloads over:443on mobile data with a valid TLS certificate and no redirect to:5001. - Confirm remote ABB sockets are on Tailscale (
sudo netstat -tnp | grep 5510shows100.64.10.10:5510 <-> 100.64.10.20:...).
Since applying these rules, the catch-all DMZ rule dropped over 3,000 unsolicited packets in the first four minutes, all remote backups and Synology Drive clients kept running without interruption, and SYNO.API.Auth hasn’t seen a single WAN brute-force attempt since.
Commentaires récents