← Back to list
2026-06-23T06:52:50.791Zcloudflare

cloudflare免费内网穿透方案,cdn加速和安全加固

cloudflare内网穿透

为什么选 Cloudflare Tunnel?

传统内网穿透常见做法:

方案 缺点
端口映射 / 公网 IP 暴露攻击面,需固定 IP
frp / ngrok 自建 需要一台公网 VPS
国内云厂商 NAT 网关 有费用,配置复杂

Cloudflare Tunnel(原 Argo Tunnel) 的核心优势:

  • 完全免费(个人/小团队够用)
  • 无需公网 IP,内网机器主动出站连接 Cloudflare
  • 自动 HTTPS,免费 SSL 证书
  • CDN 边缘加速,全球 Anycast 节点
  • 内置 WAF / DDoS 防护(免费版有基础能力)
  • Zero Trust 访问控制,可限制谁能访问

架构示意

用户浏览器
    │
    │ HTTPS
    ▼
Cloudflare 边缘节点(CDN + WAF + SSL)
    │
    │ 加密隧道(QUIC / TLS)
    ▼
cloudflared 客户端(你的内网机器)
    │
    │ 内网
    ▼
本地服务(nginx / API / SSH)

流量方向是 内网主动连出,防火墙无需开放任何入站端口。


一、前置准备

  1. 一个域名(可在 Cloudflare 注册,或迁移 NS 到 Cloudflare)
  2. 一台能跑 Docker 或二进制文件的机器(Linux / Windows / NAS 均可)
  3. Cloudflare 账号(免费)
  4. 添加站点,按提示修改域名的 NS 记录
  5. 等待 DNS 生效(通常几分钟到几小时)

注意:只有 NS 托管在 Cloudflare 的域名,才能使用 Tunnel 的自动 DNS 和 CDN 功能。


二、创建 Tunnel(内网穿透核心)

  1. 进入 Zero TrustNetworksTunnels 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图 — STARBUCKET BLOG

  2. 点击 Create a tunnel 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 2)— STARBUCKET BLOG

  3. 选择 Cloudflared 连接器 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 3)— STARBUCKET BLOG

  4. 复制安装命令中的 Token(只显示一次,请妥善保存)

方式一:Docker(推荐)

docker pull cloudflare/cloudflared:2024.12.2

docker run -d \
  --name cloudflared \
  --restart unless-stopped \
  --network host \
  cloudflare/cloudflared:2024.12.2 \
  tunnel --no-autoupdate run \
  --token <你的_TUNNEL_TOKEN>

《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 4)— STARBUCKET BLOG

方式二:环境变量传 Token

docker run -d \
  --name cloudflared \
  --restart unless-stopped \
  --network host \
  -e TUNNEL_TOKEN=<你的_TUNNEL_TOKEN> \
  cloudflare/cloudflared:2024.12.2 \
  tunnel --no-autoupdate run

方式三:systemd(Linux 原生部署)

# 安装
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 \
  -o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared

# 注册为系统服务
sudo cloudflared service install <TUNNEL_TOKEN>
sudo systemctl enable --now cloudflared
  1. 连接器安装成功后,控制台会显示对应的副本 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 5)— STARBUCKET BLOG

三、创建路由

《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 6)— STARBUCKET BLOG 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 7)— STARBUCKET BLOG 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 8)— STARBUCKET BLOG

添加成功后,会提示成功信息,dns解析会自动添加 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 9)— STARBUCKET BLOG

点击域名访问 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 10)— STARBUCKET BLOG 《cloudflare免费内网穿透方案,cdn加速和安全加固》文章正文配图(配图 11)— STARBUCKET BLOG

Comments & discussion

The first comment in each thread opens a topic. Signed-in readers can keep the conversation going under that topic.

No comments yet. Sign in to start a topic.

Start a new topic

Sign in to start a topic or join the discussion.