The Moving Parts
A tunnel has fewer parts than it first appears, but they live in three different places — your machine, your Cloudflare account, and Cloudflare's edge — and most confusion in this area is a part being looked for in the wrong place. This chapter names them all before any command depends on them.
On your machine
cloudflared is the only program. One
static binary, no installer wizard, no
database. The same binary is the agent
that holds connections open, the
management tool that creates tunnels and
routes DNS, and the local checker that
validates config files. When this guide
says "cloudflared does X", it is always
this one program wearing a different hat,
chosen by the subcommand: tunnel run,
tunnel create, tunnel ingress
validate, and so on (the full list is in
the lab's transcript
cloudflared-lab/transcripts/t00-version-and-help.txt).
The origin service is the local thing
being published — origin because it is
where answers originate. Usually a web
server on a loopback or LAN address:
http://localhost:8080. cloudflared
never contains your service; it knocks on
its door for every request. If the origin
is stopped, the tunnel is a corridor to a
shut room.
Two credential files, which beginners constantly confuse, and which chapter 5 meets in order:
cert.pem, the origin certificate, lives in~/.cloudflared/and is minted once bycloudflared tunnel login. It is an account-level credential: it lets cloudflared create and delete tunnels and edit DNS in the zones you authorised. It is the master key, and chapter 5 treats it as one.- The tunnel credentials file,
<tunnel-uuid>.json, is written bytunnel createfor one specific tunnel. It is whattunnel runpresents to prove this process is allowed to answer for this tunnel. It cannot create anything.
The config file — config.yml, by
default in ~/.cloudflared/ or
/etc/cloudflared/ — is where a named
tunnel's local half lives: which tunnel,
which credentials file, and the ingress
rules (chapter 6).
In your account
A named tunnel is an object in your
Cloudflare account with a name you chose
and a UUID Cloudflare assigned. It
exists whether or not anything is
connected to it; cloudflared tunnel
list shows the account's tunnels and
whether any connector is currently
attached. Deleting the object is a
separate, deliberate act (tunnel
delete), which is why a stopped tunnel
leaves its hostname answering with an
error rather than silence (chapter 11).
A route is the binding between the
public world and the tunnel object. For
web services it is a DNS record, made by
tunnel route dns: a CNAME in your
zone pointing your hostname at
<tunnel-uuid>.cfargotunnel.com — a name
inside Cloudflare's own domain that
means whichever edge is asked, find this
tunnel's connectors. You never manage
that target name; it is the trick in one
line. (Routes also exist for load
balancers and for private IP ranges
reached by WARP clients; this guide's
country is the DNS kind.)
At the edge
Cloudflare's edge is its worldwide anycast network — the machines that answer for your hostname. When a connector runs, it holds four long-lived connections open to the edge, spread across two data centres, so the tunnel survives one centre (or one connection) failing. A visitor's request lands at whichever edge is nearest them, and the edge sends it down one of your connector's already-open connections to cloudflared, which hands it to the origin. At no point does anything connect to your machine: every packet a visitor causes travels on a connection your machine started.
The connections speak one of two protocols: QUIC over UDP port 7844 by default, or HTTP/2 over TCP port 7844 when QUIC cannot get through (chapter 8, where the lab's probes make the difference concrete).
The quick tunnel, in this picture
A quick tunnel skips the account entirely.
cloudflared asks a small provisioning
service (api.trycloudflare.com) for a
one-off tunnel, receives a random
trycloudflare.com hostname and
short-lived credentials, and runs exactly
the machinery above — the same connector,
the same edge — with everything
disposable. That provisioning call is
also the step this guide's lab was
refused at, which is why chapter 4 is a
story about a door that would not open,
told precisely.
The dashboard alternative
Everything in this guide is driven from
the command line with a local config
file — locally managed tunnels. The
same tunnel objects can instead be
created in Cloudflare's dashboard
(Zero Trust → Tunnels), where the
config lives in the dashboard and the
machine runs one command —
cloudflared tunnel run --token <token> —
with the token standing in for the
credentials file. The two styles are not
mixed for one tunnel. This guide teaches
the local style because every part of it
can be inspected, validated and
interrogated on your own machine — and
says so, rather than pretending the
dashboard does not exist.
Check: hand someone the three lists —
machine, account, edge — from memory, and
explain which of the two credential files
a thief could use to create a tunnel
(cert.pem), and which only lets them
run one that exists.