This tutorial sets up Cloudflare Tunnel (cloudflared 2026.11.2) on an Ubuntu 24.04 VPS so you can expose web apps without opening ports 80 or 443 in the firewall and without publishing the server's IP address in DNS. It covers installing a pinned version from the official apt repository, preventing unexpected restarts (apt-mark hold and --no-update-service), configuring either a dashboard token or a validated config.yml, running the tunnel in Docker Compose and performing controlled upgrades. Package installation, version pinning, ingress rule validation and local port checks were tested on 2 December 2026 on a clean Ubuntu 24.04.5 LTS environment.
On this page
- Versions used
- When Cloudflare Tunnel makes sense
- What you will need
- 1. Keep the firewall closed to HTTP and HTTPS
- 2. Install a pinned version of `cloudflared`
- 3. Bind your application to loopback only
- 4. Run the tunnel as a system service
- 5. Docker Compose alternative (nothing installed on the host)
- 6. Controlled upgrades
- Common issues
- What was left out of the test
- Next steps

Versions used
| Component | Version | Source |
|---|---|---|
cloudflared (.deb package) |
2026.11.2 (23 Nov 2026) | cloudflared releases |
| cloudflared (Docker image) | cloudflare/cloudflared:2026.11.2 |
Docker Hub |
| Demo Docker service | traefik/whoami:v1.12.0 |
whoami repository |
| Operating system | Ubuntu 24.04.5 LTS (amd64 and arm64) |
The /usr/bin/cloudflared binary installed by the official .deb package is 39 MB on amd64, and the cloudflare/cloudflared:2026.11.2 Docker image takes about 106 MB uncompressed.
When Cloudflare Tunnel makes sense
In a standard setup, a reverse proxy like Caddy or Traefik listens on ports 80 and 443, a DNS A record points to the VPS IPv4 address and the proxy issues the TLS certificate. Cloudflare Tunnel flips that direction: cloudflared opens outbound connections from the VPS to the Cloudflare edge, and visitor HTTPS traffic travels from the edge back to your local service.
That helps in three common cases:
- Smaller attack surface on the VPS: ports 80 and 443 stay closed in
ufw, and the server IP does not appear in public DNS records. - Internal dashboards behind edge authentication: you can place Cloudflare Access in front of admin panels that should never sit open on the internet.
- No published Docker ports: when
cloudflaredruns on the same Compose network, the application container needs noports:entry on the host at all.
The trade-off is that all traffic flows through Cloudflare, subject to edge upload limits and timeouts, and TLS terminates at Cloudflare rather than directly on your server. If you want direct control on the VPS, see Traefik vs Caddy on a Docker VPS.
What you will need
- A 64-bit Ubuntu 24.04 VPS with a
sudouser (the examples usedeploy). If you still log in asroot, harden SSH andufwfirst by following First steps to secure an Ubuntu 24.04 VPS. - A domain whose DNS is managed by Cloudflare (nameservers pointed to Cloudflare). The examples use
app.example.comandapi.example.com. - For the optional Docker Compose section, Docker Engine and the Compose plugin installed as in How to install Docker and Docker Compose on Ubuntu 24.04.
cloudflared itself uses very little memory and CPU. Size the VPS according to the applications you plan to run behind the tunnel.
1. Keep the firewall closed to HTTP and HTTPS
With a tunnel, the server receives no inbound HTTP or HTTPS connections. Allow only SSH in ufw and verify the rules:
sudo ufw allow 22/tcp
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw enable
sudo ufw statuscloudflared only needs outbound connectivity: by default it connects using QUIC over UDP port 7844 and falls back to HTTP/2 over TCP port 7844 (plus HTTPS on 443 for registration and APIs). With default allow outgoing, no extra outbound rules are needed. If an upstream firewall restricts outbound traffic, allow TCP and UDP on port 7844 to the Cloudflare edge.
2. Install a pinned version of cloudflared
The official Cloudflare package repository recommends the any main suite with a dedicated GPG key on Debian-based distributions. Add the key and repository:
sudo apt-get update
sudo apt-get install -y ca-certificates curl
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list
sudo apt-get updateCheck the version available in the repository before installing:
apt-cache madison cloudflaredOn 2 December 2026 on Ubuntu 24.04.5 LTS (amd64), the output was:
cloudflared | 2026.11.2 | https://pkg.cloudflare.com/cloudflared any/main amd64 PackagesInstall that exact version, hold the package so apt upgrade does not restart the tunnel unexpectedly, and verify the binary:
sudo apt-get install -y cloudflared=2026.11.2
sudo apt-mark hold cloudflared
apt-mark showhold
cloudflared --versionapt-mark showhold should print cloudflared, and --version confirms:
cloudflared version 2026.11.2 (built 2026-11-23-13:03 UTC)3. Bind your application to loopback only
Before connecting the tunnel, make sure the local service listens only on 127.0.0.1. For a quick check without extra packages, you can start a temporary HTTP server on 127.0.0.1:8080:
python3 -m http.server 8080 --bind 127.0.0.1 &Verify the bound address with ss and check the local response:
ss -tulpn | grep 8080
curl -fsSI http://127.0.0.1:8080ss should show 127.0.0.1:8080, never 0.0.0.0:8080 or [::]:8080. Configure your real application (Node, Go, Python or Docker) to bind to 127.0.0.1 the same way.
4. Run the tunnel as a system service
Cloudflare supports two ways to manage routes: remotely managed through the dashboard, where you pass a token and edit hostnames in Zero Trust, or locally managed with config.yml, where routing stays in a versioned file on the VPS. Pick one of the two options below.
Option A: remotely managed tunnel (fastest path)
- In Cloudflare Zero Trust, open Networks > Tunnels and select Create a tunnel (type Cloudflared).
- Name the tunnel (for example,
vps-prod-01) and copy the token from the install step. - Under Public Hostname, point
app.example.comtoHTTPat127.0.0.1:8080. Cloudflare creates the DNSCNAMErecord automatically. - On the VPS, install the system service with auto-updates turned off:
sudo cloudflared service install --no-update-service PASTE_YOUR_TOKEN_HEREIn version 2026.11.2, passing a token to cloudflared service install writes the secret to a file inside the service configuration directory and configures the systemd unit to read it with --token-file, keeping the token out of ps arguments. Clear the command from shell history (or prefix it with a leading space when HISTCONTROL=ignorespace is set) and check the service:
sudo systemctl status cloudflared --no-pager
sudo journalctl -u cloudflared -n 30 --no-pagerOption B: locally managed tunnel (config.yml)
If you prefer to keep routing rules in a file on the server, create the tunnel from the CLI. tunnel login prints a URL to authorize your domain in Cloudflare:
cloudflared tunnel login
cloudflared tunnel create vps-prod-01create prints the tunnel UUID and saves its credentials at ~/.cloudflared/<UUID>.json. Copy the credentials to /etc/cloudflared/ with strict permissions and register the DNS routes:
sudo install -d -m 750 /etc/cloudflared
sudo install -m 600 ~/.cloudflared/<UUID>.json /etc/cloudflared/<UUID>.json
cloudflared tunnel route dns vps-prod-01 app.example.com
cloudflared tunnel route dns vps-prod-01 api.example.comCreate /etc/cloudflared/config.yml, replacing <UUID> with your tunnel ID:
tunnel: <UUID>
credentials-file: /etc/cloudflared/<UUID>.json
ingress:
- hostname: app.example.com
service: http://127.0.0.1:8080
- hostname: api.example.com
service: http://127.0.0.1:3000
- service: http_status:404Before installing the service, validate the configuration and test how individual URLs match:
sudo cloudflared tunnel --config /etc/cloudflared/config.yml ingress validate
sudo cloudflared tunnel --config /etc/cloudflared/config.yml ingress rule https://app.example.com
sudo cloudflared tunnel --config /etc/cloudflared/config.yml ingress rule https://other.example.comIn our test, validation returned:
Validating rules from /etc/cloudflared/config.yml
OKAnd the rule check confirmed both the matching hostname and the fallback 404:
Using rules from /etc/cloudflared/config.yml
Matched rule #0
hostname: app.example.com
service: http://127.0.0.1:8080Using rules from /etc/cloudflared/config.yml
Matched rule #2
service: http_status:404Once the rules validate, install the systemd unit with --no-update-service and check its status:
sudo cloudflared service install --no-update-service
sudo systemctl enable --now cloudflared
sudo systemctl status cloudflared --no-pagerWhenever you edit /etc/cloudflared/config.yml, run ingress validate first and restart the unit with sudo systemctl restart cloudflared.
5. Docker Compose alternative (nothing installed on the host)
If your workloads already run in Docker Compose, you can add cloudflared directly to the project's internal network. The application needs no ports: entry on the host, and the tunnel connects directly to the service name (such as http://whoami:80).
Create the directory, .env and docker-compose.yml:
mkdir -p ~/apps/tunnel-demo && cd ~/apps/tunnel-demoCLOUDFLARED_VERSION=2026.11.2
TUNNEL_TOKEN=paste-your-dashboard-token-herechmod 600 .envservices:
whoami:
image: traefik/whoami:v1.12.0
restart: unless-stopped
cloudflared:
image: cloudflare/cloudflared:${CLOUDFLARED_VERSION}
restart: unless-stopped
command: tunnel --no-autoupdate --metrics 0.0.0.0:2000 run
environment:
- TUNNEL_TOKEN=${TUNNEL_TOKEN}
depends_on:
- whoamiValidate the Compose file and start the stack:
docker compose config -q
docker compose up -d
docker compose logs -f cloudflaredIn the Zero Trust dashboard, set the Public Hostname service URL to http://whoami:80 (the Compose service name, not 127.0.0.1). The official cloudflare/cloudflared:2026.11.2 image already defaults --no-autoupdate to true, though keeping the flag in command makes the behavior explicit. Passing the secret through TUNNEL_TOKEN avoids exposing it in command arguments.
6. Controlled upgrades
When a new version appears in cloudflared releases, upgrade inside a maintenance window. For the apt install:
sudo apt-get update
apt-cache madison cloudflared
sudo apt-mark unhold cloudflared
sudo apt-get install -y cloudflared=NEW_VERSION
sudo apt-mark hold cloudflared
sudo systemctl restart cloudflared
cloudflared --versionFor Docker Compose, update CLOUDFLARED_VERSION in .env and recreate the container:
cd ~/apps/tunnel-demo
docker compose pull cloudflared
docker compose up -dCommon issues
Validation failed: The last ingress rule must match all URLs (i.e. it should not have a hostname or path filter): the catch-all rule is missing fromconfig.yml. Add- service: http_status:404as the last entry underingress:.502 Bad Gatewaywhile the service is running locally: check that the service URL useshttp://127.0.0.1:PORTrather thanhttp://localhost:PORT. On Ubuntu,localhostcan resolve to::1(IPv6) while the app listens only on IPv4 (127.0.0.1). In Docker Compose, target the Compose service name (http://whoami:80), never127.0.0.1.- Domain returns error
1033(Argo Tunnel error): thecloudflareddaemon stopped or lost all edge connections. Inspectsudo journalctl -u cloudflared -n 50 --no-pagerfor credential or network errors. - QUIC handshake fails (UDP 7844 blocked): if an upstream firewall blocks outbound UDP, test forcing HTTP/2 by adding
--protocol http2to the tunnel run command. cloudflaredlisted underkept backduringapt upgrade: expected behavior fromapt-mark hold.
What was left out of the test
The tests on 2 December 2026 ran in clean Ubuntu 24.04.5 LTS containers (amd64 and arm64) and with the cloudflare/cloudflared:2026.11.2 image. Real Cloudflare account login (cloudflared tunnel login), public DNS CNAME creation, an active connection to the Cloudflare edge and running under a full systemd VM with an active ufw firewall were left out of the test.
Next steps
- To finish securing the base server (key-only SSH, unattended security updates and fail2ban), follow First steps to secure an Ubuntu 24.04 VPS.
- If you prefer serving traffic directly from the VPS without routing through the Cloudflare edge, compare Caddy and Traefik in Traefik vs Caddy on a Docker VPS.
- To deploy a real application behind the tunnel or on a private network, see How to install n8n with Docker on a VPS and Automatic VPS backups with restic.
- If you are still choosing a server, see the Linux VPS, Docker VPS and n8n VPS plans.