Moving My Homelab's Public Side to a DMZ Edge VM
For years, everything in my homelab came in through one Traefik instance on my fileserver VM. That same VM runs the storage array and about 45 containers. It worked fine, which was the problem. If a public app had a bad enough bug, whoever exploited it would land on the machine that holds all of my data.
October made that concrete. A PHP remote code execution bug leaked and was being exploited within a day, and one of the apps I expose publicly was vulnerable for about four days before I patched it. As far as I can tell nothing happened. I still didn’t like how close the internet was to my disks.
So I split it. Public traffic now terminates on a small VM in its own DMZ VLAN, running Traefik and CrowdSec and nothing else. The fileserver only serves the few public apps that have to live there, and only to that one VM. This doesn’t buy any uptime. Everything still runs once, and if the edge VM dies, the public sites go down with it. What it buys is distance between the internet and my data.
The Layout
flowchart LR
I[Internet] --> G[UniFi gateway]
G -->|80/443| E[Edge VM in the DMZ<br/>Traefik, CrowdSec, AppSec]
E -->|HTTP :8081| F[Fileserver Traefik<br/>edge entrypoint]
E -->|HTTP| W[WordPress VM]
E -->|HTTP| A[Invoicing app]
L[LAN and WireGuard clients] -->|443| F
The DMZ is VLAN 50 on the UniFi gateway, in its own firewall zone. Nothing in the DMZ can reach the internal network except through a short list of allow rules, each one from the edge’s IP to one IP and port.
The edge VM runs Debian 13 with 4 GB of RAM. Traefik 3.8 runs on host networking and terminates TLS. CrowdSec runs next to it with the local API and AppSec (its WAF) published on loopback only, plus the nftables firewall bouncer and a blocklist importer. Certificates come from Let’s Encrypt, DNS-01 for most names and HTTP-01 for a few WordPress sites.
The media apps stayed on the fileserver because they need the disks. Its Traefik got a second entrypoint that exists only for the edge.
Why a Separate Entrypoint
I could have pointed the edge at the fileserver’s normal port 443 and been done in an afternoon. The trouble is how I protect my VPN-only services: an IP allowlist middleware that admits private addresses. The edge has a private address. If the edge forwarded into the normal entrypoint, every VPN-only service would be one DNS record away from being public.
So the fileserver has an edge entrypoint on port 8081. It trusts forwarded headers only from the edge, so backends still log the real client IP:
1
2
3
4
5
6
7
8
entryPoints:
edge:
address: ":8081"
http:
aliasHeadersStrategy: delete
forwardedHeaders:
trustedIPs:
- "192.168.50.10/32"
Nothing attaches to that entrypoint unless I write a router for it. Each public app gets one, in a file provider config, pointing at the service Docker already created. These routers carry no middlewares, because the edge already did CrowdSec, AppSec, security headers and rate limits:
1
2
3
4
5
6
http:
routers:
media-edge:
rule: "Host(`media.example.com`)"
entryPoints: [edge]
service: media@docker
The media app’s admin paths get their own router at a higher priority that always returns 403, so admin only works from the LAN or the VPN, no matter what the edge sends.
On the edge, each public name is a router with the CrowdSec middleware, pointed at the fileserver’s port 8081:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
http:
routers:
media:
rule: "Host(`media.example.com`)"
entryPoints: [websecure]
middlewares: [crowdsec@file, securityHeaders@file]
service: fileserver-edge
tls:
certResolver: le
services:
fileserver-edge:
loadBalancer:
servers:
- url: "http://192.168.10.10:8081"
Building It in Phases
I did this over about ten days, with a way back at every step.
- The DMZ VLAN and its allow rules, tested with a throwaway container on VLAN 50 before the edge VM existed.
- Monitoring moved off the fileserver. Uptime Kuma and Healthchecks now run on another VM, so the thing watching the fileserver isn’t on it.
- The edge VM, the fileserver’s
edgeentrypoint, and each backend told to trust the edge as a proxy. - LAN clients first: DNS rewrites sent the public names to the edge for everyone at home, as a trial run. Then I moved the port forwards. The first attempt got rolled back after about eight minutes (more below).
- After a quiet week, I removed the public routes and CrowdSec from the fileserver and locked port 8081 down.
Until that last step, rollback meant pointing the forwards back at the fileserver, which still had every route. That’s why I waited a week before removing anything.
What Broke
Most of what I learned came from things breaking, so this is the longest part of the post.
Docker Almost Routed My DMZ Into a Bridge
I found this one before it bit me, by luck. Docker’s default address pools are fifteen /16 networks between 172.17 and 172.31. Once those run out, it starts handing out 192.168.x.0/20 blocks. My fileserver had used all fifteen, and two newer networks were already sitting in 192.168.32.0/20 and 192.168.64.0/20. The next free block was 192.168.48.0/20, which contains my DMZ. One more compose stack and the fileserver would have sent its replies to the edge into a Docker bridge.
The fix goes in /etc/docker/daemon.json:
1
2
3
4
5
{
"default-address-pools": [
{ "base": "172.16.0.0/12", "size": 24 }
]
}
That’s 4,096 /24 networks, all clear of anything at home. It needs a Docker restart, and existing networks keep their old subnets until you remove and recreate them. Take the stacks on a network down first, remove the network, restart Docker, recreate the network, then bring the stacks back. If you start the stacks before removing the network, they just reattach to the old one.
To see where your networks landed:
1
2
docker network inspect $(docker network ls -q) \
--format ' '
UniFi IPS Blocked the Edge
On the first cutover, about two minutes after I moved the port forwards, every request from the edge to the fileserver timed out. Remote Plex, the media app and everything else on the fileserver returned 504. I moved the forwards back after about eight minutes.
UniFi’s Intrusion Prevention inspects traffic between networks, and the hop from the edge to the fileserver is plain HTTP. An ordinary DELETE from the media app during a stream matched the signature “GPL WEB_SERVER DELETE attempt”, and IPS blocked the edge’s IP for several minutes. Later, a 403 reply going the other way tripped “GPL WEB_SERVER 403 Forbidden”. An earlier unexplained 504 that afternoon turned out to be the same thing.
I found it under Insights, then Flows, by searching for the edge’s IP. Filtering by the DMZ and internal zones showed nothing, which cost me a while.
The fix was a detection exclusion for the edge’s IP with the traffic direction set to Both. Outgoing alone didn’t cover the 403 reply. That has a cost: UniFi’s IP reputation lists no longer apply to the edge, so CrowdSec and its blocklists carry that job now. Suppressing individual signatures wasn’t an option, because legitimate PUT, PATCH and DELETE requests and 401 or 403 replies trip others.
One warning if you go looking: the Exclude buttons on a Flows row act on that row’s source. Click one on a reply from the fileserver and you’ve excluded the fileserver.
CrowdSec Was Reading Logs and Parsing None of Them
After the first cutover I noticed the edge’s CrowdSec had read about 1,200 Traefik log lines and parsed zero. I had disabled the crowdsecurity/linux collection, figuring the edge didn’t need syslog parsing. That collection also carries the base parsers everything else depends on: date parsing, GeoIP enrichment and the private IP whitelists. Without it, no behavior scenario could fire. AppSec still blocked things on its own, which is why it looked like it was working.
The same afternoon I learned that crowdsecurity/non-syslog doesn’t exist in the hub anymore. Listing it made the container restart-loop, and since the Traefik bouncer fails closed, every public route returned 403 until I took it out.
If you run CrowdSec, look at this once in a while:
1
cscli metrics show acquisition
Lines parsed should keep climbing.
CrowdSec Banned My Own Phone
The second cutover worked. Within minutes, CrowdSec banned my phone while it streamed a show over LTE. The crawl scenario saw 61 requests and decided I was a scraper. A media player’s progress updates, keepalives and artwork fetches look a lot like crawling.
This never came up on the old setup because I always used the VPN when I was away, and private IPs never get banned. Ninety days of crawl bans on the old fileserver were all cloud providers.
The fix is a small CrowdSec parser that drops successful requests (2xx and 3xx) on the media routers before any scenario sees them. Failed requests on those hosts still count, so login brute forcing and 404 scans still get caught, and every other site is unaffected.
Allowlists Skip the WAF Too
I had a CrowdSec allowlist with my WAN IP and the private ranges, so nothing at home could ever get banned. Then the Uptime Kuma monitor that checks AppSec is enforcing went red. It requests /.env and expects a 403, and it got a 200.
CrowdSec’s API allowlists also bypass AppSec, so nothing from my LAN was getting WAF inspection. I cut the allowlist down to the WAN IP. Private ranges were already exempt from bans through the default whitelists parser, so for them the allowlist had only added the hole.
Hairpin NAT Had Been Hiding Missing DNS Records
The morning after the cutover, my dashboard threw certificate errors. Internal names get an AdGuard rewrite that points LAN clients at the fileserver. The dashboard’s name didn’t have one. So LAN clients got the public wildcard record, which is my WAN IP, and hairpin NAT quietly looped them back to the fileserver, which had the right certificate. That had been broken for who knows how long, and nobody could tell. After the cutover, the WAN IP led to the edge, which has no certificates for internal names.
Every internal name needs its own rewrite. I audited all of them by pulling the Host() rules out of container labels and the dynamic config and running each one through dig against both AdGuard servers. No other names were missing. Twelve old aliases didn’t resolve anywhere, and I hadn’t noticed those either.
Docker Was Using Public DNS
Containers had the same problem from a different direction. A couple of containers that called other services by their internal names started failing TLS. The cause was one line in /etc/docker/daemon.json:
1
"dns": ["1.1.1.1", "8.8.8.8"]
Every container resolved internal names through public DNS, got the WAN IP, and had been working through hairpin NAT the whole time.
This one cost more than a broken dashboard. Komodo, which deploys my compose stacks, pulls from my git server by its internal name. Every pull failed for three days without an alert, and merged updates just sat there.
I pointed daemon.json at the two AdGuard servers. For calls from one container to another, I now use the container name on a shared Docker network instead of the public hostname. A call through Traefik arrives from a Docker address, which the LAN-only allowlist rejects anyway.
Locking Down Port 8081 Took Me Down for Three Minutes
Port 8081 trusts X-Forwarded-For from the edge and has no CrowdSec in front of it. Any device on my LAN could reach it. So in the last phase I added a DOCKER-USER rule to drop anything headed for 8081 that didn’t come from the edge.
Docker publishes ports with DNAT, so by the time a packet reaches DOCKER-USER, its destination is the container’s address, not the host’s. The usual way around that is to match on conntrack’s original destination. My first version:
1
2
iptables -I DOCKER-USER 1 -p tcp -m conntrack \
--ctorigdst 192.168.10.10 --ctorigdstport 8081 ! -s 192.168.50.10 -j DROP
From the edge, requests went in and nothing came back. The rule was also matching Traefik’s replies. A reply belongs to the same conntrack entry as its request, so its original destination is still 192.168.10.10:8081, and its source is the Traefik container, which isn’t the edge. The public media apps were down for about three minutes before I rolled it back.
The fix is one flag. --ctdir ORIGINAL limits the match to packets going in the request’s direction:
1
2
iptables -I DOCKER-USER 1 -p tcp -m conntrack --ctdir ORIGINAL \
--ctorigdst 192.168.10.10 --ctorigdstport 8081 ! -s 192.168.50.10 -j DROP
The rule lives in a small systemd unit tied to docker.service, so it comes back after a reboot, and only once Docker has created the chain. My laptop now times out on port 8081 and the edge gets a 200.
Duplicate Bouncers
A small one. The blocklist importer runs as a container on the CrowdSec stack’s Docker network and authenticates with its own bouncer key. After a restart it came back on a different address, and CrowdSec registered a second bouncer, blocklist-import@172.18.0.2, next to the original. A bouncer key seen from a new IP gets a new entry. Pinning both containers to fixed addresses in the compose file stopped it, and my self-check now fails if any bouncer name has an @ in it.
Smaller Ones
- DMZ hosts resolve DNS publicly, and Healthchecks answers a bare IP with a 400. The edge’s self-check pings Healthchecks by IP with a
Hostheader. - Traefik 3.8 deprecated
underscoreHeadersStrategyin favor ofaliasHeadersStrategy. One entrypoint can’t set both to different values, so replace the old one instead of adding the new one next to it. - UniFi’s per-policy Flows Logging box does nothing when the site-wide flow logging is set to Blocked Traffic Only. Mine were ticked and greyed out, which confused me for a minute.
Keeping an Eye on It
Most of the failures above were silent. CrowdSec parsing nothing, IPS cutting off the edge and Komodo not pulling all happened without a single alert. So the edge watches itself now.
A script on the edge runs every 15 minutes and posts its log to Healthchecks. It checks that CrowdSec is running and parsing new lines, that each bouncer pulled recently, that the imported bans are in both CrowdSec and nftables, that AppSec answers, that a public site and the path to the fileserver both work, that every certificate has at least 21 days left, disk space, pending reboots and duplicate bouncers. Any failure turns the check red.
Uptime Kuma tests the public apps the way the internet reaches them. Kuma runs on the LAN, so I added extra_hosts to its container to resolve the public names to the edge for Kuma only. A per-client rewrite in AdGuard didn’t override a regular rewrite on my version, so that route didn’t work.
Unattended upgrades on the edge can reboot it at 04:45 when an update needs it, and Kuma has a maintenance window around that time.
What I Didn’t Do
I didn’t add a second Traefik or keepalived. The backends only run once, so a redundant proxy wouldn’t buy anything.
The media apps stayed on the fileserver. They need local disks for hardlinks and the SnapRAID array, and moving them would mean network storage for no real gain. I also didn’t move small stateless apps off the fileserver just to be tidy.
Where It Ended Up
Public traffic has run through the edge since late November. The fileserver serves no public routes, runs no CrowdSec, and its edge entrypoint only answers the edge. The WordPress VM and the invoicing app only trust the edge’s address for forwarded headers.
If I did it again, I’d fix Docker’s address pools and DNS first, and I’d test the IPS against the hop between VLANs before the cutover instead of during it.
While I was in all this, I also checked how much of my setup was already post-quantum. That turned into its own post.
