前提
需要绑定一个域名,切换dns服务器,并等待域名激活
SSH登录Openwrt
执行命令下载运行包
curl -L --output cloudflared-linux-arm https://github.com/cloudflare/cloudflared/releases/download/2024.4.1/cloudflared-linux-arm
根据官方提供的选择即可 https://github.com/cloudflare/cloudflared/releases
执行命令
chmod +x cloudflared-linux-arm
mv cloudflared-linux-arm /usr/bin/cloudflared
新增自启动文件
touch /etc/init.d/cloudflared
chmod +x /etc/init.d/cloudflared
编辑文件内容
vim /etc/init.d/cloudflared
文件内容如下:
#!/bin/sh /etc/rc.common
USE_PROCD=1
START=95
STOP=01
cfd_init="/etc/init.d/cloudflared"
cfd_token="这里改成教程004:你复制好的token"
boot()
{
ubus -t 30 wait_for network.interface network.loopback 2>/dev/null
rc_procd start_service
}
start_service() {
if [ $("${cfd_init}" enabled; printf "%u" ${?}) -eq 0 ]
then
procd_open_instance
procd_set_param command /usr/bin/cloudflared --no-autoupdate tunnel run --token ${cfd_token}
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_close_instance
fi
}
stop_service() {
pidof cloudflared && kill -SIGINT `pidof cloudflared`
}
token来自于cloudflare,新建隧道时自动生成
启动
/etc/init.d/cloudflared enable
/etc/init.d/cloudflared start
设置域名与内网地址即可访问
结果
访问不稳定,时不时就掉,还很慢
评论区