How to Use Cloudflared in Termux: 10 Practical Use Cases
Cloudflared (Cloudflare Tunnel) is a lightweight CLI daemon that connects your local servers and localhost environments directly to the Cloudflare edge network—allowing you to expose local web apps, SSH servers, and webhooks to the internet without port forwarding or a public IP address.
Installation in Termux
To install Cloudflared on Termux, update your repositories and install the package:
pkg update && pkg install cloudflared
10 Real-World Ways to Use Cloudflared in Termux
-
Expose a Local Web Server (Quick Tunnel): Easily share a local server running on Termux (e.g., Python HTTP, Node.js, PHP) with a free temporary
*.trycloudflare.comURL.- Command:
cloudflared tunnel --url http://localhost:8080
- Command:
-
Run a Secure DNS-over-HTTPS (DoH) Proxy: Encrypt your DNS queries by routing standard DNS traffic through Cloudflare's 1.1.1.1 secure DoH service on port 53.
- Command:
cloudflared proxy-dns --port 5053
- Command:
-
Authenticate with Your Cloudflare Account: Link Cloudflared to your Cloudflare account to manage custom domains, access policies, and permanent tunnels.
- Command:
cloudflared tunnel login
- Command:
-
Create a Permanent Named Tunnel: Create a persistent named tunnel that stays configured under your Cloudflare dashboard.
- Command:
cloudflared tunnel create my-termux-tunnel
- Command:
-
Route a Custom Domain to Localhost: Map a named tunnel directly to your custom domain or subdomain managed on Cloudflare DNS.
- Command:
cloudflared tunnel route dns my-termux-tunnel sub.example.com
- Command:
-
Run a Tunnel Using a Config File: Run persistent background tunnel configurations defined inside a
config.ymlfile.- Command:
cloudflared tunnel --config ~/.cloudflared/config.yml run
- Command:
-
Expose Termux SSH Server to the Internet: Securely expose your local Termux SSH port (8022) without opening ports on your home router.
- Command:
cloudflared tunnel --url tcp://localhost:8022
- Command:
-
Connect to a Remote SSH Host Behind Cloudflare Access: Access a remote SSH server protected behind Cloudflare Access directly from Termux.
- Command:
cloudflared access ssh --hostname ssh.example.com
- Command:
-
Run a Cloudflared Token-Based Service: Start a pre-configured Tunnel managed directly via the Cloudflare Zero Trust Dashboard using its connector token.
- Command:
cloudflared tunnel run --token YOUR_ZERO_TRUST_TOKEN
- Command:
-
List & Inspect Active Tunnels: View all active, inactive, and deleted tunnels associated with your Cloudflare account directly in terminal.
- Command:
cloudflared tunnel list
- Command:
Useful CLI Flags & Tips
- Check Installed Version:
cloudflared --version - View Command Help:
cloudflared tunnel --help - Enable Verbose Debug Logging:
cloudflared --loglevel debug tunnel --url http://localhost:8080 - Specify Custom Configuration Path:
cloudflared --config /path/to/config.yml run
Pro Tip: When running local web servers in Termux, make sure your server is running (e.g.,
python -m http.server 8080) before initiating thecloudflaredtunnel command.