Moving my public website into an isolated DMZ
My public website now runs in its own DMZ VLAN. The only container with any network access can reach DNS and Cloudflare and nothing else, and the web containers have no network route at all. This is how I designed it, what broke on the way, and how I proved it holds.
Why
The site started the easy way: a Cloudflare Tunnel into cloudflared on my trusted LAN, through the same Traefik proxy that serves my internal apps, to an nginx container. No ports were open on the firewall, which felt safe.
But the tunnel only protects the way in. If nginx or the visitor counter were ever compromised, the attacker would be sitting on the LAN next to Pi-hole, Portainer, my workstations and every admin interface in the house. A public service shouldn't share a network, or a proxy, with the things I trust most.
The goal: anything internet-facing lives in a network that can reach only what it strictly needs, so a compromise there stays there.
Design
Building it
- A new VLAN on the firewall. I added a DMZ VLAN interface in OPNsense with its own /24, DHCP off and Unbound listening on it, so the DMZ has a DNS server it can use without reaching anything else.
- Tagging it through the switch. The Docker host had to be on Ethernet (a macvlan can't ride on Wi-Fi), with a static IP. On the switch, the DMZ VLAN is tagged on the host's port and the firewall uplink, and nowhere else. My first attempt tagged the access point's port instead; reading the port map back caught it.
- Putting one container in the DMZ. A Docker macvlan network on the VLAN sub-interface gives cloudflared its own fixed IP in the DMZ, as if it were a separate machine. Docker's IP range is limited to a small block, and every DMZ container gets a fixed address so nothing can take cloudflared's.
- Keeping the web containers off every network. nginx and the counter sit on an internal Docker network (
internal: true) shared only with cloudflared. They have no default route: no internet, no LAN, not even the Docker host. - Firewall rules for the DMZ, in order (first match wins):
| # | Action | What | Why |
|---|---|---|---|
| 1 | Pass | DNS (TCP and UDP 53) to the firewall's DMZ address | cloudflared has to resolve Cloudflare's names |
| 2 | Block | Anything to the firewall itself | No path to the firewall's admin interfaces |
| 3 | Block | All private ranges (RFC 1918) plus 100.64.0.0/10 | No LAN, no other VLANs, no Tailscale network |
| 4 | Pass | TCP and UDP 443 and 7844 to Cloudflare's published IP ranges | The tunnel itself: HTTPS, HTTP/2 and QUIC |
| — | Deny | Everything else (default) |
A separate rule on the LAN blocks LAN to DMZ, so the separation holds in both directions.
- Switching the tunnel over. In Cloudflare, the tunnel's routes now point at
http://website:80, nginx on the internal network, instead of at Traefik. Traefik went back to serving internal apps only. I saved the old stack definition first, so rolling back was one paste away.
What broke
The tunnel wouldn't come up: cloudflared couldn't resolve Cloudflare's hostnames. It took four separate fixes, each found by testing one layer at a time from inside the DMZ.
| Step | What I saw | Cause | Fix |
|---|---|---|---|
| 1 | DNS queries from the DMZ timed out | Unbound wasn't listening on the new interface | Added the DMZ interface to Unbound's listen list |
| 2 | Still no answers; the interface behaved oddly | The VLAN was attached to the wrong parent NIC | Corrected the parent and rebooted the firewall |
| 3 | Queries reached the firewall but were blocked | The pass rule's destination was my Local_DNS alias (Pi-hole on the LAN), not the firewall's DMZ address | Destination set to "DMZ address"; this also closed an unintended DMZ-to-LAN path |
| 4 | Short lookups worked, larger ones failed | The rule allowed UDP only; DNS falls back to TCP for larger answers | Protocol set to TCP and UDP |
Step 3 is the one I'm glad I hit. The broken rule would have "worked" if I had pointed the DMZ at Pi-hole, but only by giving the DMZ a hole into the LAN, which is exactly what this project was meant to prevent. Fixing it properly gave the DMZ its own resolver on the firewall and nothing more.
Proving it
A design is only a claim until it's tested, so I tried to break out of the DMZ the way an attacker would. cloudflared's image has no shell, so for its tests I borrowed its network with a throwaway container (docker run --rm --network container:cloudflared alpine …): same IP, same firewall rules.
| Test | Expected | Result |
|---|---|---|
| Web containers reach the internet | Blocked | Timed out |
| Web containers reach the Docker host | Blocked | Timed out |
| cloudflared reaches Cloudflare | Allowed | Passed (/cdn-cgi/trace answered) |
| cloudflared reaches a non-Cloudflare site (GitHub) | Blocked | Timed out |
| cloudflared reaches the LAN, other VLANs, the firewall GUI, the Tailscale range | Blocked | All timed out |
| nmap scan from the DMZ | Nothing reachable | Everything filtered |
| LAN reaches the DMZ | Blocked | Blocked by rule |
| IPv6 in the DMZ | None | None configured |
| Privileged containers or a mounted Docker socket | None | None |
| The scan from the DMZ raises an IDS alert | Alert | Suricata flagged it and the alert reached Slack |
| Site from a phone on mobile data | Loads, counter works | Passed |
The firewall's live log during these tests showed only DNS and Cloudflare traffic passing; every other attempt appeared as a block.
Hardening on top
With the network boundary in place, I tightened every layer above and below it.
- Egress limited to Cloudflare. At first the DMZ could reach any internet address on 443 and 7844. I replaced "any" with a URL Table alias that pulls Cloudflare's published IPv4 ranges daily. Cloudflare's tunnel servers sit inside those ranges, so the tunnel stayed healthy, but a compromised container can no longer download tools or send data anywhere else. Tested: Cloudflare answers, GitHub times out.
- Container hardening. cloudflared runs read-only with every Linux capability dropped and
no-new-privileges. nginx is read-only with tmpfs for its scratch space. The counter runs as a non-root user, read-only, with no capabilities, and stores only daily salted hashes of visitors, never IP addresses. - Edge protection. Cloudflare's managed WAF rules, a custom rule that returns 403 to common exploit probes (
/.env,/wp-adminand similar), and a rate limit on the counter API, backed by nginx's own per-visitor limit. DNSSEC is on. - Browser-side lockdown. A Content-Security-Policy that allows only the site's own files: no third-party scripts, styles or fonts (the fonts are self-hosted). I switched off Cloudflare features that inject scripts (Web Analytics, email obfuscation, bot JavaScript detection) rather than loosening the policy for them. The headers score A+ (120/100) on Mozilla Observatory.
- A way to report problems.
/.well-known/security.txt(RFC 9116) tells researchers how to reach me; nginx serves that one file and still blocks every other dot-path.
Lessons and what's next
- "No open ports" is not the same as isolated. A tunnel controls the way in; segmentation controls what a compromise can reach. Both are needed.
- The easy fix can quietly undo the design. Pointing the DMZ at my LAN DNS server would have made the errors disappear and opened the hole the project existed to close.
- Test like an attacker, and keep the evidence. Each claim on my site ("the DMZ can reach only DNS and Cloudflare") is backed by a test I can repeat.
- Narrow allow-lists beat broad ones. Limiting egress to Cloudflare's ranges took one alias and turned "the internet" into "one provider".
Next on the list: pinning image versions instead of latest, moving nginx to an unprivileged image, and watching Cloudflare's security events for a while to see what the edge rules actually stop.