Cloudflare in Termux: Basic Commands & Usage
Introduction
Cloudflare Tunnels (formerly Argo Tunnel) provide a secure way to connect your local Termux servers to the public internet without the need for router port forwarding or public IP addresses. By running the cloudflared daemon, you can create encrypted tunnels that route traffic through Cloudflare's global network, ensuring high security and stability for your web applications.
Installation
Ensure your Termux environment is updated before installing the Cloudflare daemon.
1. Update and Upgrade Packages
pkg update && pkg upgrade -y
2. Install Cloudflared
pkg install cloudflared -y
3. Verify Installation
cloudflared --version
Quick Tunnels (Temporary)
Quick tunnels are the fastest way to expose a local port. They generate a random trycloudflare.com URL and do not require a Cloudflare account.
Expose Local Ports
Run these commands depending on your local server's port:
# For a Python Server (Port 8080) cloudflared tunnel --url http://localhost:8080 # For an Apache Server (Port 80) cloudflared tunnel --url http://localhost:80 # For Node.js/NodeREPL (Port 3000) cloudflared tunnel --url http://localhost:3000
Force IPv4 Mode
If you encounter connectivity issues, you can force the tunnel to use IPv4:
cloudflared tunnel --url http://localhost:8080 --edge-ip-version 4
Named Tunnels (Permanent)
Named tunnels offer more stability and allow you to use your own custom domains. These require a Cloudflare account.
1. Login to Cloudflare
cloudflared tunnel login
2. Create a Named Tunnel
cloudflared tunnel create <tunnel_name>
3. Management Commands
# List all tunnels cloudflared tunnel list # Run a named tunnel cloudflared tunnel run <tunnel_name> # Delete a tunnel cloudflared tunnel delete <tunnel_name>
Key Tips
- Local Server: You must have a local server running (e.g., Python, PHP, or Node.js) before the tunnel can route traffic to it.
- Security: Tunnels provide automatic HTTPS, encrypting data between Cloudflare and the end user.
- Stopping: Press
CTRL + Cto terminate the tunnel session.