支付
-
首先进行安装cloudflared client客户端服务
cd /d C:\Windows\System32\cloudflare-
-
报错:
2023-09-17T07:28:57Z INF Installing cloudflared Windows service cloudflared service is already installed at Cloudflared; 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 uninstallto clean up the existing service and then try again this command或报错:
Cannot establish a connection to the service control manager: Access is denied
就先
cloudflared service uninstall,然后在进行安装cloudflared client客户端服务。
补充:可以用来更新或删除客户端服务里的令牌指令:在 Windows 系统中删除「服务」的 4 种方法 - 系统极客 (sysgeek.cn)
-
登录
cloudflared.exe login
会返回一个pem文件
创建Tunnel
cloudflared.exe tunnel create <NAME>
就是自定义的隧道名,如:test;
然后会在.cloueflared文件下返回一个json文件,文件名格式为:Tunnel ID.json,Tunnel ID就是类似这样的一串字符串:654494fc-3a3e-4343-xxxx-8867b1e33c84。
配置DNS记录
cloudflared.exe tunnel route dns <NAME> rdp.chenkai.fun
注意这里.cloueflared文件下的yaml文件编码要为utf-8,否则报错yaml:invalid trailing UTF-8 octet
编写配置文件
# 隧道的 UUID, 就是登录凭证的json文件名称
tunnel: 654494fc-3a3e-4343-xxxx-8867b1e33c84
# 鉴权文件的全路径,注意替换为自己的
credentials-file: C:\Users\Lenovo.cloudflared\654494fc-3a3e-4343-xxxx-8867b1e33c84.json
ingress:
# 你的freenom二级域名
#- hostname: chenkai.fun
# service: http://localhost:5173
# 你的freenom二级域名
- hostname: rdp.chenkai.fun
service: rdp://localhost:3389
# 默认错误404
- service: http_status:404
配置完成后,验证一下配置文件是否正确:
cloudflared.exe tunnel ingress validate
测试运行
cloudflared.exe --config=C:\Users\Lenovo.cloudflared\config.yaml tunnel run
远程桌面配置
cloudflared.exe access rdp --hostname rdp.chenkai.fun --url localhost:3000
other
实现内网穿透的方式还有很多,比如:natapp、frp、cpolar、ngrok等等等等。看个人需求去使用:
- natapp免费的会不定期随机域名/端口,然后免费版也不支持自定义域名,要自定义域名的话,还需要备案的域名,参考链接:natapp自定义域名和NetApp绑定自主域名;
- frp似乎得先整个公网服务器才行;
- 后两个前者是国内的,后者是国外的,据说不太稳定,而且cpolar免费版的是不固定域名;
- Sunny-Ngrok是国内的,但是用https隧道协议时,要求域名有ssl证书,且端口号限制在443,参考:Sunny-Ngrok实现自定义域名内网穿透和ngrok https 自定义域名本地部署HTTPS环境 注意项解读。
所以最后我选了cloudflare tunnel(就是国内使用的话,延迟会比较高)。
参考链接:
- CloudFlare Argo Tunnel配置 - 实现内网穿透 - 码农教程 (manongjc.com)
- 使用cloudflare tunnel免费内网穿透,实现网站的外网访问和远程桌面 - 知乎 (zhihu.com)
- 如何使用Cloudflare配置rdp穿透 - 知乎 (zhihu.com)
- cloudflared内网穿透实现Windows远程桌面 | 娃娃Code (dollcode.cn)
- 内网穿透(NAT 穿透)原理+工具(部分无需管理员权限)内网穿透原理noobiee的博客-CSDN博客
- 内网穿透(NAT 穿透)原理+工具(部分无需管理员权限)nat工具noobiee的博客-CSDN博客
- 内网穿透你真的了解吗? - 知乎 (zhihu.com)