v0.6 · 开源免费 · MIT License

一条命令
localhost → 公网域名

基于 Cloudflare Tunnel 的极简 CLI,免费、安全、无需公网 IP,支持 macOS / Linux / Windows

$ cftunnel quick 3000
正在下载 cloudflared...
cloudflared 已下载
✔ 隧道已启动: https://portrait-liverpool-essentials.trycloudflare.com
6
支持平台
1
条命令穿透
0
费用
MIT
开源协议
Features

为什么选 cftunnel

把 Cloudflare Tunnel 的繁琐流程封装成极简 CLI

免域名模式

cftunnel quick <端口>,零配置生成 *.trycloudflare.com 临时公网地址,无需账户和域名

极简操作

init → create → add → up,4 条命令搞定自有域名穿透,DNS CNAME 自动创建和清理

全平台覆盖

macOS (Intel / Apple Silicon)、Linux (amd64 / arm64)、Windows 10+ (amd64 / arm64)

安全免费

基于 Cloudflare 全球网络加密传输,无需公网 IP,完全免费使用

访问保护

--auth user:pass 一键启用密码保护,内置鉴权代理中间件,无需外部依赖,支持 WebSocket 透传

系统服务

cftunnel install 一键注册开机自启 — macOS launchd / Linux systemd / Windows Service

便携模式

程序同级目录放一个 portable 空文件,配置/日志/二进制全部就地存储,U 盘携带

下载加速

内置多镜像源轮询,自动选择最快通道,国内用户也能秒装 cloudflared

自更新

cftunnel update 一键升级到最新版,自动检测 GitHub Release

一键清理

cftunnel destroy 自动删隧道 + 删 DNS 记录 + 删本地配置,不留残余

Architecture

工作原理

cftunnel 是 cloudflared 的智能管理层,不是代理本身

localhost:3000
你的本地服务
cftunnel
CLI 管理层
cloudflared
Tunnel 守护进程
Cloudflare Edge
全球 CDN 网络
公网用户
通过域名访问
cftunnel 负责:自动下载 cloudflared · 创建/管理 Tunnel · 推送 ingress 配置 · 管理 DNS 记录 · 注册系统服务
流量路径:本地服务 ⇄ cloudflared ⇄ Cloudflare Edge ⇄ 公网用户(全程加密,cftunnel 不经手流量)
Compare

cftunnel vs 原生 cloudflared

同样的 Cloudflare Tunnel,更简单的操作方式

操作原生 cloudflaredcftunnel
免域名穿透cloudflared tunnel --url 手动操作cftunnel quick <端口>
创建隧道登录浏览器 + 手动配置cftunnel create my-tunnel
DNS 记录手动去 Dashboard 创建 CNAME自动创建和清理
多路由管理手动编辑 YAML 配置add / remove / list
开机自启手动写 systemd / launchdcftunnel install
清理资源手动删隧道 + 删 DNS + 删配置cftunnel destroy
自更新cftunnel update
便携模式portable 文件启用
密码保护需配合 Cloudflare Access--auth user:pass 内置鉴权
下载加速仅 GitHub 原始地址多镜像源自动轮询
Windows 检测自动检测 Win10+ 版本
Commands

命令速查

所有命令一览,复制即用

quick <端口>
免域名模式,一键穿透,Ctrl+C 退出自动清理
quick <端口> --auth user:pass
免域名模式 + 密码保护,访问需登录验证
init
初始化配置,输入 API Token 和 Account ID
create <名称>
创建 Cloudflare Tunnel
add <名> <端口>
添加路由,自动创建 DNS CNAME 记录
add <名> <端口> --auth user:pass
添加路由 + 密码保护
remove <名称>
删除路由,同步清理 DNS 记录
up / down
启动 / 停止 cloudflared 守护进程
install
注册系统服务,开机自启
uninstall
卸载系统服务
list
查看当前所有路由配置
logs
查看 cloudflared 运行日志
destroy
一键清理:删隧道 + 删 DNS + 删配置
update
自更新到最新版本
Troubleshooting

故障排查

常见问题与解决方案

QUIC 连接超时

failed to dial to edge with quic: timeout

代理/防火墙拦截了 UDP。cftunnel v0.6.1+ 已默认使用 HTTP/2(TCP)。运行 cftunnel uninstall && cftunnel install 重装服务即可。

DNS fake-ip 劫持

cloudflared 解析到 198.18.0.x

Clash 等代理的 TUN 模式劫持了 DNS。将 cloudflared 进程加入 TUN 绕行列表,或将 *.argotunnel.com 加入 fake-ip-filter。

1033 错误

DNS CNAME 指向旧 Tunnel ID

运行 cftunnel remove <名称>cftunnel add 重建路由,自动修正 DNS 记录。

530 错误

cloudflared 未连接到 Edge

运行 cftunnel logs -f 查看实时日志,根据具体错误参考上述对应方案排查。

Install

安装

单二进制文件,零运行时依赖

$ curl -fsSL https://raw.githubusercontent.com/qingchencloud/cftunnel/main/install.sh | bash

支持 macOS Intel / Apple Silicon、Linux amd64 / arm64

PS> irm https://raw.githubusercontent.com/qingchencloud/cftunnel/main/install.ps1 | iex

支持 Windows 10+ (amd64 / arm64),自动添加到 PATH

$ git clone https://github.com/qingchencloud/cftunnel.git
$ cd cftunnel
$ make build

需要 Go 1.21+

也可以从 GitHub Releases 手动下载

Quickstart

快速上手

两种模式,按需选择

1

免域名模式

零配置,临时分享和调试
$ cftunnel quick 3000

✔ 隧道已启动:
https://xxx-yyy-zzz.trycloudflare.com

# Ctrl+C 退出,域名自动失效
2

自有域名模式

固定域名,稳定持久
$ cftunnel init
$ cftunnel create my-tunnel
$ cftunnel add app 3000 --domain app.example.com
$ cftunnel up

# app.example.com → localhost:3000
Desktop

桌面客户端

不想敲命令?试试可视化管理界面

cftunnel Desktop

基于 Wails 构建的跨平台 GUI,仪表盘一键启停、免域名模式、路由管理、内置终端,支持 macOS / Windows / Linux

项目详情 晴辰导航