Cheat Sheet
Cloudflare CLI Cheat Sheet
Quick commands for tunnels, DNS, SSL, and page rules
Tunnel Management
# Install
cloudflared tunnel login
# Create tunnel
cloudflared tunnel create my-tunnel
# List tunnels
cloudflared tunnel list
# Route DNS to tunnel
cloudflared tunnel route dns my-tunnel example.com
# Delete tunnel
cloudflared tunnel delete my-tunnel
# Run tunnel
cloudflared tunnel run my-tunnel
Config File (YAML)
# ~/.cloudflared/config.yaml
tunnel: my-tunnel
credentials-file: /root/.cloudflared/my-tunnel.json
ingress:
- hostname: app.example.com
service: http://localhost:8080
- hostname: example.com
service: http://localhost:80
- service: http_status:404
Service Management
# Install as system service
cloudflared service install
# Start/Stop
systemctl start cloudflared
systemctl stop cloudflared
systemctl restart cloudflared
systemctl status cloudflared
# View logs
journalctl -u cloudflared -f
Multiple Hostnames (Single Tunnel)
ingress:
- hostname: site1.com
service: http://localhost:8897
- hostname: site2.com
service: http://localhost:8898
- hostname: site3.com
service: http://localhost:8899
- service: http_status:404
API Token Management
# Login (generates cert.pem)
cloudflared tunnel login
# API tokens in env
export TUNNEL_TOKEN=eyJ...
cloudflared tunnel run --token $TUNNEL_TOKEN
DNS via API
# List zones
curl -X GET "https://api.cloudflare.com/client/v4/zones" \
-H "Authorization: Bearer $TOKEN"
# Add DNS record
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"type":"A","name":"example.com","content":"1.2.3.4","proxied":true}'
# Purge cache
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE/purge_cache" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"purge_everything":true}'
Useful Flags
# Run in foreground with verbose logging
cloudflared tunnel --loglevel debug run my-tunnel
# Metrics endpoint
cloudflared tunnel --metrics localhost:2000 run my-tunnel
# Health check
curl http://localhost:2000/metrics