# Cloudflare Quick Tunnels (cloudflared)

Expose local services to the internet without registration or configuration.

## Install cloudflared

```bash
# Download (use proxy if in China)
curl -x http://127.0.0.1:7890 -L https://github.com/cloudflare/cloudflared/releases/download/2024.12.2/cloudflared-linux-amd64 -o /tmp/cloudflared
sudo install -m 755 /tmp/cloudflared /usr/local/bin/cloudflared
cloudflared --version
```

## Quick Tunnel (no account needed)

```bash
cloudflared tunnel --url http://localhost:3000
```

Output:
```
Your quick Tunnel has been created! Visit it at:
https://random-name.trycloudflare.com
```

- URL is **temporary** — changes each time cloudflared restarts
- **HTTPS** by default (valid certificate)
- No registration, no config file needed
- Free, no rate limits for quick tunnels

## Background Usage

```bash
# Run in background, log to file
cloudflared tunnel --url http://localhost:3000 > /tmp/cloudflared.log 2>&1 &

# Extract URL from log
grep "trycloudflare.com" /tmp/cloudflared.log
```

## With Proxy (for cloudflared's own connection)

If the machine needs a proxy to reach Cloudflare's network:
```bash
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
cloudflared tunnel --url http://localhost:3000
```

Note: In some network environments, running without proxy works better for cloudflared since it uses QUIC protocol. Try both.

## Pitfalls

### No output in background mode
`cloudflared` writes tunnel URL to **stderr**. Use `2>&1` to capture:
```bash
cloudflared tunnel --url http://localhost:3000 2>&1
```

### Tunnel URL changes on restart
For persistent URLs, register a free Cloudflare account and create a named tunnel:
```bash
cloudflared tunnel login
cloudflared tunnel create my-tunnel
cloudflared tunnel route dns my-tunnel myapp.example.com
```

### Other tools comparison
| Tool | Registration | Persistent URL | Reliability |
|------|-------------|----------------|-------------|
| cloudflared quick | No | No (random) | High |
| cloudflared named | Yes (free) | Yes | High |
| ngrok | Yes | No (free) / Yes (paid) | High |
| localtunnel | No | No | Low (often blocked) |
| bore | No | No | Medium |
| serveo | No | No | Low (often down) |
