skip to content

How does a locally-managed Cloudflare Tunnel built with cloudflared tunnel create, route dns and run differ from a remotely-managed tunnel run with a token?

level: middleimportance: should knowfreq 35%

answer

  1. where the routes live
  2. account certificate versus per-tunnel secret
  3. config.yml on each host
  4. run --token

basics

~20 s

A locally-managed tunnel keeps its routes in a config.yml on each host and needs cert.pem to create and route it. A remotely-managed tunnel stores its routes on Cloudflare, and the host only runs cloudflared tunnel run --token.

solid answer

~40 s

Locally managed: `cloudflared tunnel login` writes `cert.pem`, which can manage every tunnel in the account. `cloudflared tunnel create staging` writes a `<UUID>.json` credentials file that runs only that tunnel. You write the ingress rules in `config.yml`, add the CNAME with `cloudflared tunnel route dns`, and start with `cloudflared tunnel run`. Each change is a file edit and restart on every host. Remotely managed: you create the tunnel and its published application routes in the dashboard or API, and the host runs `cloudflared tunnel run --token <TOKEN>` (or `--token-file`). Cloudflare pushes one configuration to every connector, and it replaces any local ingress rules. Cloudflare recommends remote management for most cases.

code

bash · 4 lines
bash
cloudflared tunnel login
cloudflared tunnel create staging
cloudflared tunnel route dns staging staging-api.example.com
cloudflared tunnel --config /etc/cloudflared/config.yml run staging

go deeper

for a junior

Recall the two styles: a config.yml with a credentials file for locally-managed tunnels, a token for remotely-managed ones, and the create, route dns, run sequence.

for a middle

Explain what each file grants. cert.pem manages every tunnel in the account, a credentials file or token runs one tunnel, and a pushed remote configuration replaces local ingress rules.

for a senior

Show the operational consequences: per-host config drift with local files, cert.pem kept off servers, --overwrite-dns protecting existing records, and tokens kept off command lines.

for a principal

Weigh where routing should live for a team. One centrally stored configuration with reviewed API changes against files in version control that every host must carry identically.

## Two ways to own a tunnel's configuration Every Cloudflare Tunnel has a name, a UUID and a set of routes. The difference between the two management styles is **where that configuration lives** and **what the host needs in order to run it**. - A **locally-managed** tunnel is created with `cloudflared tunnel create` and configured by a `config.yml` on the host. - A **remotely-managed** tunnel is created in the dashboard or through the API, and its configuration is stored on Cloudflare. Cloudflare recommends remotely-managed tunnels for most uses. Locally-managed ones are documented for local development, testing and legacy configurations. ## The locally-managed workflow Take the staging API on a private network with no public IP: 1. **`cloudflared tunnel login`** opens a browser, asks you to pick a domain, and writes **`cert.pem`**, an account certificate, to the default `cloudflared` directory. It contains an API token, and it lets its holder **create, delete, route and list every tunnel in the account**. 2. **`cloudflared tunnel create staging`** registers the tunnel, prints its UUID and writes a **credentials file**, `<UUID>.json`. That file only lets its holder **run this one tunnel**, and it does not expire. 3. A **`config.yml`** names the tunnel, the credentials file and the ingress rules: ```yaml tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef credentials-file: /etc/cloudflared/6ff42ae2-765d-4adf-8112-31c55c1551ef.json ingress: - hostname: staging-api.example.com service: http://localhost:9000 - service: http_status:404 ``` 4. **`cloudflared tunnel route dns staging staging-api.example.com`** creates the CNAME to `<UUID>.cfargotunnel.com`. It needs `cert.pem`, and it refuses to replace an existing record unless you pass **`--overwrite-dns`** (`-f`). 5. **`cloudflared tunnel run staging`** connects. Use `--config <path>` if the file is not in the default directory. If you name the tunnel by UUID, `run` needs the credentials file but not `cert.pem`. Any routing change is a file edit followed by a restart, on **every host** that runs the tunnel. ## The remotely-managed workflow 1. Create the tunnel in the dashboard, or with the API using `config_src: "cloudflare"`. 2. Add **published application routes** (hostname to service) and their origin parameters in the dashboard or with the API. Adding a route in the dashboard also creates the DNS record. 3. On the host, run the connector with the **tunnel token**: `cloudflared tunnel run --token <TOKEN>`, `--token-file <path>`, or the `TUNNEL_TOKEN` environment variable. `cloudflared service install <TOKEN>` installs it as a system service. The host holds no `cert.pem` and no ingress rules. Cloudflare pushes the stored configuration to each connector, and that pushed configuration **replaces** any local ingress rules, so editing a `config.yml` on the host does not change the routes. `cloudflared tunnel token <NAME>` can print the token of an existing tunnel. ## Side by side | | Locally-managed | Remotely-managed | |---|---|---| | Created with | `cloudflared tunnel create` | Dashboard or API | | Routes live in | `config.yml` on each host | Cloudflare | | DNS record | `cloudflared tunnel route dns` | Created when a route is added | | Host needs | Credentials file plus `config.yml` | The token | | Account-wide secret on a machine | `cert.pem`, wherever tunnels are created | None | | Changing a route | Edit every host's file and restart | One edit, applied to all connectors | ## Choosing between them For the staging API and the admin dashboard of this scenario, the questions that decide it are practical: - **How many hosts run the tunnel?** With two or more replicas, local files can drift apart, while a remote configuration is pushed to all of them. - **Who changes routes, and how?** Remote routes can be changed through the API from a reviewed pipeline. Local routes are changed by whoever can edit and restart every host. - **What may sit on a server?** A remote connector needs only its token. The local workflow needs `cert.pem` wherever tunnels are created and routed. The token is not a different kind of credential from the credentials file. It is an encoded form of the same tunnel credentials (account, tunnel ID and secret), which is why `cloudflared tunnel token --cred-file <path> <NAME>` can write one out as the other. ## The credentials to protect - **`cert.pem`** is the dangerous one, because it manages every tunnel in the account. Keep it off servers, and revoke it by deleting its API token from the dashboard. - The **credentials file** and the **token** each grant "run this tunnel" and nothing else. Anyone who has one can still attach a connector. Store them as secrets. A remotely-managed tunnel's token can be **rotated**.

  • Which machines need cert.pem in the locally-managed workflow?
    Only the machine that creates, routes, lists or deletes tunnels. `cloudflared tunnel run` with the tunnel's UUID needs just the credentials file. Since `cert.pem` can manage every tunnel in the account, keep it off servers that only run a tunnel, and revoke it by deleting its API token if it leaks.
  • What does cloudflared tunnel route dns do when the hostname already has a record?
    It does not replace the existing record unless you pass `--overwrite-dns` (`-f`). That protects a hostname already in use from being silently moved onto the tunnel. Remember that the CNAME and the tunnel are independent: the record can exist while the tunnel is stopped.

  • The tunnel credentials file can create and delete other tunnels in the account
  • Editing config.yml on the host changes the routes of a remotely-managed tunnel
  • cert.pem is needed on every host that runs the tunnel
  • cloudflared tunnel route dns also adds the ingress rule to config.yml
  • A tunnel token is only a name; anyone can see it without risk

Assumes Cloudflare's platform as of 2026-10-10, where remotely-managed tunnels are the recommended default and locally-managed ones are documented for development, testing and legacy setups.