2

cloudflare tunnel使用

 2 years ago
source link: https://www.bboy.app/2022/01/26/cloudflare_tunnel%E4%BD%BF%E7%94%A8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

cloudflare tunnel使用

发表于 2022-01-26

更新于 2022-01-27

分类于

linux

20220126-1.png

内网穿透工具现在有很多了,但是大部分都要有自己的一个公网服务器,比如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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK