01The starting point
Services went through Cloudflare in proxy mode, then through a port 443 forward to the home reverse proxy. The proxy hid the address in DNS, but the port stayed open: anyone who knew the public address could bypass Cloudflare and talk directly to the reverse proxy.
02The reversal
With a tunnel, the direction of the connection is reversed. A small program, cloudflared, runs at home and opens outbound connections to Cloudflare on port 7844 (UDP for QUIC, TCP for HTTP/2 as fallback). Visitors arrive at Cloudflare, which sends their requests down those already-open connections. On the router there is nothing left to forward, and no port to scan.
Each hostname is routed to a specific service, top to bottom. The last rule, mandatory, catches everything else and returns an error, instead of letting a request land on a service by default.
# cloudflared config.yml (locally managed tunnel)
tunnel: <tunnel-id>
credentials-file: /etc/cloudflared/<tunnel-id>.json
ingress:
- hostname: status.example.com
service: http://192.0.2.10:3001
- hostname: home.example.com
service: http://192.0.2.20:8123
- service: http_status:404 # everything else: refused03Local file or dashboard
A tunnel can also be managed remotely: routes are declared in the Cloudflare dashboard and the connector only receives a token. This is the recommended method with Docker, and the one used here: the cloudflared container only knows its token, kept in a protected file. The two don’t mix: with a token, config.yml is not read.
With local management, cloudflared checks the file before loading it, and tells you which rule will catch a given URL:
cloudflared tunnel ingress validate
cloudflared tunnel ingress rule https://status.example.com04Identity before the service
A tunnel publishes; it doesn’t protect. Admin interfaces therefore sit behind Cloudflare Access: the visitor must authenticate before their request reaches the service. A page that must stay public (a status page, for example) gets an exception (a “Bypass” policy) limited to its own path, not the whole hostname.
05Migration traps
The internal firewall still matters: the machine running cloudflared must be able to reach each service, and only those. A service on another VLAN needs its rule. Outbound, port 7844 must be allowed if the firewall also filters outgoing traffic.
The reverse proxy must no longer answer unknown names. Otherwise a third-party domain pointed at the old address would land on a default site. A default server block that closes the connection without a response (code 444 in nginx) settles it for whatever still goes through it.
Close the port forward last, once every tunnel route is tested: the reverse order cuts services during the migration.
06Verify from outside
The test that counts is done off the network, on 4G: services answer by name, and the public address no longer answers on port 443.
# From an outside connection (4G):
curl -sI https://status.example.com | head -1 # expected: HTTP/2 200 via Cloudflare
nc -vz -w 3 203.0.113.10 443 # expected: failure, nothing listensKey takeaways
- The tunnel reverses direction: outbound connections (7844), no inbound port.
- One hostname, one service, and a final rule that refuses everything else.
- Token (dashboard) or config.yml: one or the other, not both.
- Publishing isn’t protecting: Access checks identity before the service.
- Close the port forward last, then test from 4G.
Documentation-reserved names and addresses.
Official sources
- Cloudflare Tunnel: configuration filedevelopers.cloudflare.com/tunnel/advanced/local-management/configuration-file/
- Cloudflare Tunnel: tunnel with firewalldevelopers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/configure-tunnels/tunnel-with-firewall/
- Cloudflare Access: policiesdevelopers.cloudflare.com/cloudflare-one/access-controls/policies/
- nginx: return directive (444)nginx.org/en/docs/http/ngx_http_rewrite_module.html#return