Cloudflare内网穿透

前期准备

Cloudflare的账号:Cloudflare Dashboard | Manage Your Account
一个域名(必须

加入Free计划(新号)

登录Cloudflare,点击Zero Trust

输入,自定义的名团队名称

选择一个Free的计划

点击继续付款

这里什么都不用填,直接点击下一步,跳转之后,直接点击取消并退出(右上角)

重新在点击Zero Trust

创建内网穿透隧道

如下下图,点击创建隧道

自定义一个隧道名称

选择一个自己操作系统类型进行安装

隧道连接

我选择debian的类型环境

首次创建,右侧有连接的命令

添加cloudflare gpg键

1
2
sudo mkdir -p --mode=0755 /usr/share/keyrings
curl -fsSL https://pkg.cloudflare.com/cloudflare-main.gpg | sudo tee /usr/share/keyrings/cloudflare-main.gpg >/dev/null

将此仓库添加到您的apt仓库

1
echo 'deb [signed-by=/usr/share/keyrings/cloudflare-main.gpg] https://pkg.cloudflare.com/cloudflared any main' | sudo tee /etc/apt/sources.list.d/cloudflared.list

安装cloudflared

1
sudo apt-get update && sudo apt-get install cloudflared

连接

1
sudo cloudflared service install eyJhIjoiODViZjQwNTNlOGUyZDNWRhMWU1MjM5IiwicyI6xxxIk16UTBNV0UzWXpRdE1tSmtaaTAwWTJKakxXSXlNRFV0WlRKbVlXTmhNalEwTkRkbSJ9

成功连接之后,重新刷新一下,cloudflare的网站

点击管理隧道

点击查看隧道

就可以查看到隧道而连接情况了

内网穿透

以内网搭建的Halo网站为例

点击隧道配置的按钮

点击选择公共主机名

点击添加公共主机名

服务填入内网搭建的服务,这里输入nw的三级域名(可以不填写)

设置完成之后,验证内网穿透的结果。

成功访问内网搭建的服务。

常见的错误

出现连接的报错信息

1
2
3
2025-04-12T12:21:13Z INF Using Systemd
2025-04-12T12:21:13Z ERR error generating service template error="cloudflared service is already installed at /etc/systemd/system/cloudflared.service; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command"
cloudflared service is already installed at /etc/systemd/system/cloudflared.service; if you are running a cloudflared tunnel, you can point it to multiple origins, avoiding the need to run more than one cloudflared service in the same machine; otherwise if you are really sure, you can do `cloudflared service uninstall` to clean up the existing service and then try again this command

输入如下命令进行卸载

1
2
3
web@ubuntu:~/Desktop$ sudo cloudflared service uninstall
2025-04-12T12:23:14Z INF Using Systemd
2025-04-12T12:23:15Z INF Linux service for cloudflared uninstalled successfully

卸载完成之后,在重新连接

1
sudo cloudflared service install eyJhIjoiODViZjQwNTNlOGUyZDNWRhMWU1MjM5IiwicyI6xxxIk16UTBNV0UzWXpRdE1tSmtaaTAwWTJKakxXSXlNRFV0WlRKbVlXTmhNalEwTkRkbSJ9

Cloudflare内网穿透
https://skilladd.org/2025/04/12/10.cloudflare内网穿透/
Author
skilladd
Posted on
April 12, 2025
Licensed under