创建一个目录存放需要的工具

mkdir -p /opt/tunnel
cd /opt/tunnel

#下载三个工具
wget -O cloudflared https://ghfast.top/https://github.com/cloudflare/cloudflared/releases/download/2025.1.0/cloudflared-linux-amd64

#gost
wget -O- https://ghfast.top/https://github.com/go-gost/gost/releases/download/v3.0.0-nightly.20250110/gost_3.0.0-nightly.20250110_linux_amd64.tar.gz | tar xzv gost

#cf优选自动工具与IP
wget -O cfd https://ghfast.top/https://github.com/fscarmen/cfd_return/raw/refs/heads/main/cfd/cfd-linux-amd64
wget -O ip https://ghfast.top/https://github.com/fscarmen/cfd_return/raw/refs/heads/main/cfd/ip.txt

#使用screen 创建窗口
screen -US server

然后本地服务端执行下面命令

#服务端命令
#本地设备/软路由
./gost -L=relay+mws://testuser:ttpwd@:回源端口?bind=true&path=/ws

然后Ctrl+A+D退出当前窗口

再建一个窗口

screen -US cfd

执行以下命令

./cfd -file /opt/tunnel/ip

跑完优选后继续Ctrl+A+D退出当前窗口

再建第三个窗口

screen -US tunnel

创建两个配置文件

tunnel.json 用于保存隧道json信息,可用以下链接获取Cloudflare services

如以下信息:{"AccountTag":"SD85hoFOHJOIJOIUONCHBG","TunnelSecret":"SDcjoujoiuottyJaQ=","TunnelID":"隧道ID"}

将以上内容填入tunnel.json文件里

tunnel.yml 隧道配置文件,内容如下

tunnel: 隧道ID
credentials-file: /opt/tunnel/tunnel.json

ingress:
  - hostname: 隧道域名
    service: http://localhost:回源端口
  - service: http_status:404

然后启动隧道

cloudflared tunnel --protocol http2 --logfile /tmp/cloudflared.log --edge-ip-version auto --config /opt/tunnel/tunnel.yml run

以上操作完成后服务端设置已完成

成功后可看到CF后台隧道状态已显示

然后是远程VPS客户端的配置

远程客户端只需安装GOST

wget -O- https://ghfast.top/https://github.com/go-gost/gost/releases/download/v3.0.0-nightly.20250110/gost_3.0.0-nightly.20250110_linux_amd64.tar.gz | tar xzv gost

然后启用GOST

#客户端命令 #落地VPS 
./gost -D -L rtcp://:映射到服务端的端口/127.0.0.1:远程需要映射给服务端的端口 -F relay+mwss://testuser:ttpwd@CF隧道域名:443&path=/ws

完成部署后使用其他客户端工具进行连接测试