Zero-config Cloudflare Tunnels for Developers.
Expose localhost to the world in seconds with a custom domain.
cftunn is a lightweight CLI tool that automates the creation of Cloudflare Tunnels. It abstracts away the complexity of creating tunnels, routing DNS, and configuring ingress rules into a single command.
Designed for developers who want the ease of ngrok but with their own custom domains and the security/performance of Cloudflare.
- One-Command Setup: No YAML configs, no UUID management. Just
cftunn <port> <domain>. - Automatic DNS: Automatically manages CNAME records for your domain.
- Smart Auth: seamlessly integrates with your existing
cloudflaredlogin or API tokens. - Self-Healing: Automatically cleans up or rotates credentials for existing named tunnels to ensure a successful connection.
- Safe: Prompts for confirmation before overwriting existing DNS records.
- Cross-Platform: Works on macOS and Linux.
You need Go 1.20+ installed.
go install github.com/thatjuan/cftunn@latestOr clone the repo:
git clone https://github.com/user/cftunn.git
cd cftunn
make install1. cloudflared
This tool relies on the official Cloudflare Tunnel daemon.
- macOS:
brew install cloudflared - Linux: Installation Instructions
2. Authentication
You need to be authenticated with Cloudflare.
-
Method A: Interactive Login (Recommended)
Run this once to authorize your machine:cloudflared tunnel login
This will open your browser and generate a
cert.pemfile. -
Method B: API Token (CI/CD friendly)
Set the environment variable:export CLOUDFLARE_API_TOKEN=your_api_tokenRequired Permissions:
Zone:DNS:Edit,Account:Cloudflare Tunnel:Edit.
Expose your local server running on port 3000 to dev.example.com:
cftunn 3000 dev.example.comcftunnchecks for the tunnelcftunn-dev-example-com.- If it doesn't exist, it creates it.
- It checks if
dev.example.comexists in your DNS. - It routes the tunnel to that hostname (prompting if it needs to overwrite).
- It starts the tunnel, forwarding traffic to
localhost:3000.
Usage:
cftunn [PORT] [DOMAIN] [flags]
Flags:
-h, --help help for cftunn
We welcome contributions!
- Fork the repository.
- Clone your fork:
git clone https://github.com/YOUR_USERNAME/cftunn.git cd cftunn - Install dependencies:
go mod tidy
Use the included Makefile:
make build
# Output binary is ./cftunnCurrently, manual testing is required due to the integration nature of the tool (requires real Cloudflare API).
- Mocking: Future improvements should include interfaces for the Cloudflare API to allow unit testing.
Please open an issue on GitHub with:
- Your OS version.
- The command you ran.
- The error output (redacted of any tokens/secrets).
- Output of
cloudflared --version.
MIT License. See LICENSE for details.
This is a community project and is not affiliated with Cloudflare. Use it at your own risk.