CloudFlare内网穿透教程
下载程序到盒子里:
https://github.com/cloudflare/cloudflared/releases
自己选择对应版本下载,
32位arm平台选择【cloudflared-linux-arm】
64位arm平台选择【cloudflared-linux-arm64】
我打包了arm和arm64位的,可供下载
蓝奏下载地址cloudflared.zip 密码cf
cloudflared.zip
下载好命名cloudflared放到放到/usr/bin/
给权限和登陆
1
2
| chmod -R 0777 /usr/bin/cloudflared
cloudflared login
|
此时终端会显示一个https:// 的网址,复制到浏览器打开,登录自己的cloudflare账号,选择要绑定的域名,并获取自动下载的授权文件
创建一个隧道
cloud 是你创建的隧道名称,记好,后面要用,这个名称可自定义
得到隧道的id
1
| cloudflared tunnel create cloud
|
配置文件config.yml到/etc/cloudflared/
1
2
3
4
5
6
7
| tunnel: 275fe7bb-5948-45a0-bda7-30da7d154ddf
credentials-file: /root/.cloudflared/275fe7bb-5948-45a0-bda7-30da7d154ddf.json
ingress:
- hostname: cloud.2091k.cn
service: http://127.0.0.1
- service: http_status:404
|
#这个ID在/root/.cloudflared里
1
2
| mkdir -p /etc/cloudflared/
vi /etc/cloudflared/config.yml
|
在运行
1
| cloudflared tunnel route dns cloud cloud.2091k.cn
|
这时就可以在CF平台DNS看到解析的记录
配置最后自启动
1
2
3
| cloudflared service install #运行自启动安装
systemctl start cloudflared #启动服务
systemctl status cloudflared #查看运行状态 可随时ctrl + c 中止。
|
如需要添加多个子域名
配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| tunnel: mytunnel
credentials-file: /root/.cloudflared/你的隧道UUID.json
ingress:
# 云盘
- hostname: cloud.2091k.cn
service: http://127.0.0.1
# 小程序API后台
- hostname: api.2091k.cn
service: http://127.0.0.1:8080
# 打印解析后台
- hostname: print.2091k.cn
service: http://127.0.0.1:8081
# 兜底404,必须写最后一行
- service: http_status:404
|
添加新的子域名到DNS
1
| cloudflared tunnel route dns mytunnel print.baidu.com
|
最后 修改完 yml 后,重启 cloudflared 服务才会加载新 ingress 规则
1
| sudo systemctl restart cloudflared
|
添加其他域名
- 新增一段 hostname,示例第二个域名:
shturl.cc/oN
1
2
3
4
5
6
7
8
| tunnel: 275fe7bb-5948-45a0-bda7-30da7d154ddf
credentials-file: /root/.cloudflared/275fe7bb-5948-45a0-bda7-30da7d154ddf.json
ingress:
- hostname: cloud.2091k.cn
service: http://127.0.0.1
- hostname: shturl.cc/oN
service: http://127.0.0.1:8080
- service: http_status:404
|
- 然后在cf对应域名下面手动添加DNS解析
- CF内网穿透位置
联网-Tunnels
1
2
| 类型-CNAME
目标-隧道ID.cfargotunnel.com
|
- 然后重启服务,就可以在CF后台看到新添加的域名
1
| sudo systemctl restart cloudflared
|
输入cloud.2091k.cn就可以访问了
cloud.2091k.cn