Skip to content

Cloudflare Tunnel: expose a private origin without opening inbound ports

Run cloudflared on a private origin, create a tunnel, route DNS, define ingress rules, and operate it as a systemd service — no public IP, no firewall holes.

You have an internal web app — a Grafana, a wiki, a Jenkins, a customer staging environment — sitting on a VM with no public IP. The shortcut is to NAT a port through the edge firewall and slap basic auth on it. Cloudflare Tunnel removes that whole class of attack surface: the origin opens an outbound TLS connection to the Cloudflare edge, you point a hostname at the tunnel, and traffic flows in over the existing connection. No inbound port, no public IP, no VPN concentrator to maintain.

How to verify

Before you start, confirm what you have. The tunnel binary is cloudflared, installed from the Cloudflare apt/yum repo or as a single static binary. On the origin:

cloudflared --version
# cloudflared version 2026.4.0 (built 2026-04-...)

# Tunnel must be authenticated against your Cloudflare account
cloudflared tunnel login
# Opens a browser; pick the zone, writes ~/.cloudflared/cert.pem

# List tunnels you already own
cloudflared tunnel list

# Once a tunnel is running, verify the outbound connections
ss -tnp | grep cloudflared
# Four ESTABLISHED connections to 198.41.x.x:7844 (QUIC) — that's healthy

If ss shows fewer than 4 edge connections, the tunnel is degraded and you will see intermittent 530 errors at the edge. The fix is almost always egress firewall: UDP 7844 outbound to Cloudflare’s edge IPs must be allowed.

What’s happening

A tunnel is a long-lived outbound connection from your origin to the Cloudflare edge. The cloudflared daemon dials four QUIC connections to four different colocation facilities and keeps them open. When a request arrives at the edge for a hostname routed to that tunnel, the edge picks one of the four connections, multiplexes the request over it, and cloudflared proxies the request to the origin service named in your ingress rules. The reply travels back over the same connection.

The mental shift is that the origin is no longer a network endpoint — it’s a software endpoint. There is no IP address to scan, no port to fingerprint, no TCP handshake to attempt. Anyone trying to reach the app must come through Cloudflare’s edge, which means WAF, rate limiting, Access policies, and bot management all apply by default. You also stop maintaining a site-to-site VPN: there is no IPsec, no IKEv2, no concentrator to patch.

Private originno public IPcloudflaredUDP/78444 x QUICEdge PoP AEdge PoP BEdge PoP CEdge PoP DCloudflareWAF + AccessUserHTTPS
cloudflared dials four QUIC connections out to the edge — no inbound port, no public IP on the origin.

The procedure

  1. Install cloudflared on the origin. On Ubuntu/Debian, add the Cloudflare apt repo and apt install cloudflared. On Alpine or anywhere static, grab the release binary from pkg.cloudflare.com/cloudflared and drop it in /usr/local/bin. Verify with cloudflared --version — pin to a known release in your config management.

  2. Authenticate the host. Run cloudflared tunnel login. This opens a browser, you pick the zone, and a cert.pem lands in ~/.cloudflared/. That cert is what authorizes the host to create and operate tunnels against your account. Treat it like an API key — never commit it.

  3. Create the tunnel. A tunnel is an account-level object identified by a UUID:

    cloudflared tunnel create internal-apps
    # Tunnel credentials written to /root/.cloudflared/<UUID>.json
    # Created tunnel internal-apps with id <UUID>

    The <UUID>.json file contains the long-lived secret the daemon uses to authenticate. Move it to /etc/cloudflared/ and lock it down with chmod 600.

  4. Write the config. At /etc/cloudflared/config.yml:

    tunnel: <UUID>
    credentials-file: /etc/cloudflared/<UUID>.json
    
    ingress:
      - hostname: grafana.internal.example.com
        service: http://localhost:3000
      - hostname: jenkins.internal.example.com
        service: http://localhost:8080
        originRequest:
          httpHostHeader: jenkins.internal.example.com
      - hostname: ssh.example.com
        service: ssh://localhost:22
      # catch-all required at the bottom
      - service: http_status:404

    Ingress rules are matched top-down. The final http_status:404 is required — without it, cloudflared refuses to start. One tunnel can serve many hostnames; you don’t need a tunnel per app.

  5. Route DNS. Each hostname needs a CNAME at the edge pointing to <UUID>.cfargotunnel.com. The CLI does it for you:

    cloudflared tunnel route dns internal-apps grafana.internal.example.com
    cloudflared tunnel route dns internal-apps jenkins.internal.example.com
    cloudflared tunnel route dns internal-apps ssh.example.com

    These are proxied (orange-cloud) CNAMEs. If you create them manually in the dashboard, make sure the proxy toggle is on or the lookup will return the literal cfargotunnel.com hostname to clients, which they cannot reach.

  6. Run as a service. Don’t run cloudflared tunnel run in a screen session. Install the systemd unit:

    cloudflared service install
    systemctl enable --now cloudflared
    systemctl status cloudflared
    journalctl -u cloudflared -f

    The unit reads /etc/cloudflared/config.yml. Restart-on-failure is on by default; the log will show all four edge connections coming up within ~5 seconds of start.

  7. Add Access in front (recommended). A tunnel exposes the app to the public internet via the proxied hostname — anyone who guesses the URL can hit the login page. Put a Cloudflare Access policy on each hostname so a Google/Okta SSO check runs at the edge before the request is multiplexed to the origin. See /en/knowledge-base/cf-access-sso-gate-applications/ for the policy shape.

Common pitfalls

  • Egress firewall blocks UDP 7844. Default in many corporate networks; you’ll see the tunnel flap between QUIC and HTTP/2 fallback. Allow UDP 7844 outbound to Cloudflare or accept the slower fallback.
  • One credentials file per host. Don’t copy <UUID>.json to a second host expecting HA — both daemons will fight for the same tunnel. Use a replicated tunnel (multiple cloudflared replicas authenticated against the same tunnel ID, supported since 2022) or run two separate tunnels with DNS-level failover.
  • Missing the catch-all ingress rule. cloudflared refuses to start without - service: http_status:404 at the bottom of the ingress: block. The error in the log is explicit.
  • Origin app rejects the Host header. Apps like Jenkins or Grafana sometimes check the Host: header against their configured base URL. Set originRequest.httpHostHeader per hostname or fix the app config.
  • SSH/RDP without cloudflared access ssh on the client. Routing ssh:// works, but the client still needs a cloudflared access ssh --hostname ssh.example.com ProxyCommand entry in ~/.ssh/config, otherwise the SSH handshake will not flow over the tunnel.

For client engagements with a mix of internal staging environments and production apps living on private VLANs, we use Cloudflare Tunnel as the default exposure pattern — no VPN concentrator, no inbound NAT, every hostname gated by Access. The runbook above is the template; the per-client work is auditing what’s currently NAT’d through the firewall, retiring the holes, and wiring the SSO policy. That’s the operating model we run in Managed Operations.