← All notes

Moving my public website into an isolated DMZ

Joseph Henry Cariazo ·

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

Request path before and after the move to the DMZ After the move, a compromise in the public site stays in the DMZ Before Trusted LAN, next to Pi-hole, Portainer, workstations Cloudflare edge cloudflared Traefik nginx, counter After DMZ VLAN Internal network: no route out Cloudflare edge cloudflared nginx counter
Before, every hop after Cloudflare sat on the trusted LAN and shared the internal proxy. After, cloudflared is the only container with network access, alone in the DMZ, and nginx and the counter sit on an internal network with no route anywhere.

Building it

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Firewall rules for the DMZ, in order (first match wins):
#ActionWhatWhy
1PassDNS (TCP and UDP 53) to the firewall's DMZ addresscloudflared has to resolve Cloudflare's names
2BlockAnything to the firewall itselfNo path to the firewall's admin interfaces
3BlockAll private ranges (RFC 1918) plus 100.64.0.0/10No LAN, no other VLANs, no Tailscale network
4PassTCP and UDP 443 and 7844 to Cloudflare's published IP rangesThe tunnel itself: HTTPS, HTTP/2 and QUIC
—DenyEverything else (default)

A separate rule on the LAN blocks LAN to DMZ, so the separation holds in both directions.

  1. 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.

StepWhat I sawCauseFix
1DNS queries from the DMZ timed outUnbound wasn't listening on the new interfaceAdded the DMZ interface to Unbound's listen list
2Still no answers; the interface behaved oddlyThe VLAN was attached to the wrong parent NICCorrected the parent and rebooted the firewall
3Queries reached the firewall but were blockedThe pass rule's destination was my Local_DNS alias (Pi-hole on the LAN), not the firewall's DMZ addressDestination set to "DMZ address"; this also closed an unintended DMZ-to-LAN path
4Short lookups worked, larger ones failedThe rule allowed UDP only; DNS falls back to TCP for larger answersProtocol 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.

TestExpectedResult
Web containers reach the internetBlockedTimed out
Web containers reach the Docker hostBlockedTimed out
cloudflared reaches CloudflareAllowedPassed (/cdn-cgi/trace answered)
cloudflared reaches a non-Cloudflare site (GitHub)BlockedTimed out
cloudflared reaches the LAN, other VLANs, the firewall GUI, the Tailscale rangeBlockedAll timed out
nmap scan from the DMZNothing reachableEverything filtered
LAN reaches the DMZBlockedBlocked by rule
IPv6 in the DMZNoneNone configured
Privileged containers or a mounted Docker socketNoneNone
The scan from the DMZ raises an IDS alertAlertSuricata flagged it and the alert reached Slack
Site from a phone on mobile dataLoads, counter worksPassed

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.

Lessons and what's next

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.

← All notes