Bboysoul's Blog

首页 公告 RSS

cloudflare tunnel使用

January 26, 2022 本文有 628 个字 需要花费 2 分钟阅读

简介

内网穿透工具现在有很多了,但是大部分都要有自己的一个公网服务器,比如frp nps ngrok,今天介绍一个cloudflare的东西,Cloudflare Tunnel原来其实叫argo tunnel

操作

首先下载它的二进制文件

wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm

因为我用的是树莓派,所以下载的是arm,其他平台的可以在

https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation

这里下载

下载完成之后修改下名字

mv cloudflared-linux-arm cloudflared

之后就是登陆cloudfalre

./cloudflared tunnel login

这里会生成一个url让你去登陆,类似下面的

Please open the following URL and log in with your Cloudflare account:

https://dash.cloudflare.com/argotunnel?callback=https%3A%2F%2Flogin.cloudflareaccess.org%2FVjZz97cLpFFrlM_--7uqNs1kZ4GaQBlU%3D

Leave cloudflared running to download the cert automatically.

如果你在cloudflare上有多个域名,那么选择一个域名登陆就好了

授权完成之后,终端会输出下面类似的东西

2022-01-26T06:30:13Z INF Waiting for login...
You have successfully logged in.
If you wish to copy your credentials to a server, they have been saved to:
/root/.cloudflared/cert.pem

之后创建一个隧道

./cloudflared tunnel create nas

比如我创建了一个叫nas的隧道来暴露我的nas

创建完成之后会显示

Tunnel credentials written to /root/.cloudflared/7b9-2e1b-46-80-cdfb.json. cloudflared chose this file based on where your origin certificate was found. Keep this file secret. To revoke these credentials, delete the tunnel.

Created tunnel nas with id 7b9-2e1b-46-80-b0f828c2fb

记住这个id然后进行下一步

./cloudflared tunnel list

显示你创建的隧道

之后创建一个配置文件

比如config.yml

添加

tunnel: 隧道id
credentials-file: /root/.cloudflared/隧道id.json

ingress:
  - hostname: nas.bboysoul.cn
    service: http://10.10.100.244
  - service: http_status:404

之后添加dns,dns可以直接命令行添加,比如

cloudflared tunnel route dns nas nas.bboysoul.cn

或者手动添加个cname

隧道id.cfargotunnel.com

之后运行隧道

./cloudflared tunnel run

默认会读取

/etc/cloudflared/config.yml

下面的文件

或者你可以指定下配置文件的路径

./cloudflared tunnel --config path/config.yaml run

之后直接访问你的域名就好了

缺点

因为国内的网络缘故,所以在稳定性等方面其实是不太好的

欢迎关注我的博客www.bboy.app

Have Fun


Tags:

本站总访问量 本站总访客数