Cloudflare 内网穿透
date
Oct 18, 2023
slug
Technology-Sharing-00
status
Published
tags
Cloudflare
技术分享
summary
将内网的服务器映射到公网上。
type
Post
Tunnel(隧道)可以做什么
- 将本地网络的服务暴露到公网,可以理解为内网穿透。
- 自动为你的域名提供 HTTPS 认证。
- 将非常规端口服务转发到 80/443 常规端口。
- 为你的服务提供额外保护认证。
前置条件
持有一个域名
将域名DNS解析托管到Cloudflare
Visa信用卡或Paypal
服务器内网穿透
在这里填写Team name,随意填写

选择第一个免费服务

添加付款信息

创建隧道
完成后,在首页控制面板左侧点击Zero Trust,
跳转到新的页面Access Tunnels中,创建一个Tunnel,名字起什么都可以

选择Cloudflared部署方式
Tunnel 需要通过 Cloudflared 来建立云端与本地网络的通道
根据自己的内网服务器来选择安装的系统版本
因为研究室用的是树莓派(arm64)安装的yunohost,我这里选择的是Debian-arm64

复制完成后通过终端ssh链接到自己的内网服务器,粘贴此命令等待安装完成
为你的域名配置一个子域名(Subdomain),Path留空,URL处填写内网的IP地址
注:如果在Yunohost上选择内网穿透时请打开这个选项
因为Yunohost注册时选择的官方域名,本地会有自己签名的证书,但是Cloudflare会颁发证书,进行内网穿透时会起冲突,主页会一只显示502

访问配置的三级域名
Tunnel 中可以添加多条三级域名来跳转到不同的内网服务,在 Tunnel 页面的 Public Hostname 中新增即可。
ssh内网穿透
内网服务器已成功穿透到公网,但是无法远程后台管理,所以还使用cloudflare来实现ssh内网穿透。
在隧道中添加一个ssh域名;类型选择ssh,url输入服务器IP

在应用中添加ssh



其余不用修改,选择下一步
在输入一名字,验证方式选择邮箱,添加邮箱
拉到底部,选择下一步

拉到底部选在ssh,添加应用

浏览器打开设置到的域名,输入绑定的邮箱接收验证码

验证服务器中用户身份
