先前做法
先前, 我们是通过脚本来和 cloudflare 配合来不断将域名和 ipv6 进行一个绑定来修改, 但是这样我的服务器就是一个直接的出站, 并没有经过什么加速. 所以相比通过代理的方式, 速度会慢很多.
脚本如下:
#!/bin/bash
# CHANGE THESE
auth_email="[email protected]" #你的CloudFlare注册账户邮箱,your cloudflare account email address
auth_key="188f5f3f1ba73b37fd2a0" #你的cloudflare账户Globel ID ,your cloudflare Globel ID(就是我的个人资料里的global api key,应该就是用来做身份识别用的)
zone_name="050626.xyz" #你的域名,your root domain address
record_name="alist.050626.xyz" #完整域名,your full domain address
record_type="AAAA" #A or AAAA,ipv4 或 ipv6解析
ip_index="local" #use "internet" or "local",使用本地方式还是网络方式获取地址
eth_card="enp1s0" #使用本地方式获取ip绑定的网卡,默认为eth0,仅本地方式有效,the default ethernet card is eth0
ip_file="ip.txt" #保存地址信息,save ip information in the ip.txt
id_file="cloudflare.ids"
log_file="cloudflare.log"
if [ $record_type = "AAAA" ];then
if [ $ip_index = "internet" ];then
ip=$(curl -6 ip.sb)
elif [ $ip_index = "local" ];then
if [ "$user" = "root" ];then
ip=$(ifconfig $eth_card | grep 'inet6' | cut -f2 | awk '{ print $2}' | grep -v '^::1$' | grep -v '^fe80' | grep -v '^f[d|c]' | head -1)
else
ip=$(/sbin/ifconfig $eth_card | grep 'inet6' | cut -f2 | awk '{ print $2}' | grep -v '^::1$' | grep -v '^fe80' | grep -v '^f[d|c]' | head -1)
fi
else
echo "Error IP index, please input the right type"
exit 0
fi
elif [ $record_type = "A" ];then
if [ $ip_index = "internet" ];then
ip=$(curl -4 ip.sb)
elif [ $ip_index = "local" ];then
if [ "$user" = "root" ];then
ip=$(ifconfig $eth_card | grep 'inet'| grep -v '127.0.0.1' | grep -v 'inet6'|cut -f2 | awk '{ print $2}')
else
ip=$(/sbin/ifconfig $eth_card | grep 'inet'| grep -v '127.0.0.1' | grep -v 'inet6'|cut -f2 | awk '{ print $2}')
fi
else
echo "Error IP index, please input the right type"
exit 0
fi
else
echo "Error DNS type"
exit 0
fi
# 日志 log file
log() {
if [ "$1" ]; then
echo -e "[$(date)] - $1" >> $log_file
fi
}
# SCRIPT START
log "Check Initiated"
#判断ip是否发生变化,check the ip had been changed?
if [ -f $ip_file ]; then
old_ip=$(cat $ip_file)
if [ $ip == $old_ip ]; then
echo "IP has not changed."
exit 0
fi
fi
#获取域名和授权 get the domain and authentic
if [ -f $id_file ] && [ $(wc -l $id_file | cut -d " " -f 1) == 2 ]; then
zone_identifier=$(head -1 $id_file)
record_identifier=$(tail -1 $id_file)
else
zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*' | head -1 )
record_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records?type=${record_type}&name=$record_name" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "Content-Type: application/json" | grep -Po '(?<="id":")[^"]*')
echo "$zone_identifier" > $id_file
echo "$record_identifier" >> $id_file
fi
#更新DNS记录 update the dns
update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_identifier" \
-H "X-Auth-Email: $auth_email" \
-H "X-Auth-Key: $auth_key" \
-H "Content-Type: application/json" \
--data "{\"type\":\"$record_type\",\"name\":\"$record_name\",\"content\":\"$ip\",\"ttl\":1,\"proxied\":false}")
#反馈更新情况 gave the feedback about the update statues
if [[ $update == *"\"success\":true"* ]]; then
message="IP changed to: $ip"
echo "$ip" > $ip_file
log "$message"
echo "$message"
else
message="API UPDATE FAILED. DUMPING RESULTS:\n$update"
log "$message"
echo -e "$message"
exit 1
fi
然后, 在 cloudflare 中配置一条 DNS 记录 (先设为 AAAA, 然后就是先输入一次 ipv6, 之后更改就会通过脚本自动推送的了, 不设置代理即云朵为灰色)
但是, 显然这样的方法, 速度会很慢. 所以就有了以下改进.
通过 Cloudflare 的 Tunnel 和 alist 绑定
[!Tip] 因为 alist 一开始是直接通过本服务器的自身 ipv6 链路出站的, 所以速度很慢. 现在换成通过 cloudflare 节点加速的话, 配置就改变一下. (其实就是通过 cloudflare 代理), 所以要删除原先的
DNS记录才行
所以, 先设置 /opt/alist/data 的 config.yaml 中的 force_https 为 false
还有就是因为已经通过 cloudflare 代理了, 所以我们不用自己设置端口号为 443, 我们可以通过设置 http://localhost:5244 这个本地的端口就行, 免得发生冲突
用 cloudflared 将 Alist 暴露为 https://yourname.cloudflare.workers.dev
Cloudflare 代理可自动走优质线路,无需暴露真实 IPv6
几乎所有地区都有高质量访问速度
适合你的场景(远端用户多,原生 IPv6 差)
非常好,你已经使用了 IPv6 + DDNS 访问 https://alist.050626.xyz,接下来我们要做的是:
使用 Cloudflare Tunnel 给你的 Alist 提速(绕过 IPv6 出口限制)
目标
通过 Cloudflare Tunnel 实现:
- 不暴露真实 IP(保护隐私)
- 自动走 Cloudflare 高质量 CDN 节点
- 提升远端访问速度(避免你当前的“IPv6 出站带宽被限速”问题)
步骤一:在服务器上安装 cloudflared
以 Arch 为例(你是 Arch 用户):
sudo pacman -S cloudflared
若是其他系统:
# Debian/Ubuntu
sudo apt install cloudflared
# RedHat/CentOS
sudo yum install cloudflared
若没有, 就要通过 wget 下载 deb 包然后 dpkg 解压安装
步骤二:登录并授权 cloudflared
cloudflared tunnel login
这会打开浏览器登录 Cloudflare,授权后你可以创建 tunnel。
步骤三:创建 tunnel 并绑定 Alist 服务
cloudflared tunnel create alist-tunnel
会输出一个 tunnel ID,例如:
Created tunnel alist-tunnel with ID 12345678-aaaa-bbbb-cccc-123456abcdef
步骤五:创建配置文件
默认目录在 ~/.cloudflared/config.yml, 你也要配置在 /etc/cloudflared/ 目录中:
tunnel: 12345678-aaaa-bbbb-cccc-123456abcdef # 你的 tunnel ID
credentials-file: /home/<user>/.cloudflared/12345678-aaaa-bbbb-cccc-123456abcdef.json # 你的json文件
ingress:
- hostname: alist.050626.xyz
service: http://localhost:5244 # Alist 默认端口
- service: http_status:404
确保 localhost:5244 是 Alist 的监听地址和端口。
步骤六:创建 DNS 记录 + 启动 tunnel
将 tunnel 与 Cloudflare DNS 绑定:
cloudflared tunnel route dns alist-tunnel alist.044454.xyz
然后运行 tunnel:
cloudflared tunnel run alist-tunnel
如需后台运行,可以用 systemd 或 --no-autoupdate 参数。
成功后你可以
- 使用
https://alist.044454.xyz高速访问 Alist(通过 Cloudflare 节点加速) - 客户端访问走的是 Cloudflare 的全球加速网络,而不是你服务器自身出站 IPv6 链路
可选:设置为 systemd 后台服务
sudo cloudflared service install
这样服务器重启后自动启动 tunnel。
验证
- 用浏览器打开
https://alist.044454.xyz - 使用
curl -v https://alist.044454.xyz,应看到 Cloudflare 代理标识 - 远程测速明显比直接 IPv6 快,尤其是下载时
通过 systemd 来自动运行
一键启用后台服务
sudo cloudflared service install
这个命令会自动为你生成 systemd 服务文件并启用开机启动。
然后启动服务
sudo systemctl start cloudflared
设置开机自动运行(通常默认启用)
sudo systemctl enable cloudflared
检查运行状态
systemctl status cloudflared
会看到 tunnel 正常运行,输出中包含 alist-tunnel 和你的域名。
验证
- 浏览器访问你的域名
https://alist.050626.xyz - 用命令查看:
curl -I https://alist.050626.xyz
看是否有响应头包含:
HTTP/1.1 200
HTTP/2 200
cf-ray: xxxx
server: cloudflare
说明已通过 Cloudflare Tunnel 代理 ✅
完整示例:
HTTP/1.1 200 Connection established
HTTP/2 200
date: Fri, 06 Jun 2025 05:12:42 GMT
content-type: text/html
cf-cache-status: DYNAMIC
speculation-rules: "/cdn-cgi/speculation"
report-to: {"group":"cf-nel","max_age":604800,"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v4?s=UOD6%2Fislw4MqZ951XaKh0jczFwySa4dshAcWMzNleVhuay3NDTkvlRwkqr%2BRv5PBb%2FPMW7aQ2mZFerZSiEZxvZpKE4CPVIpvxGXTdWO5ph4%3D"}]}
nel: {"report_to":"cf-nel","success_fraction":0.0,"max_age":604800}
server: cloudflare
cf-ray: 94b56a8e293909f0-HKG
alt-svc: h3=":443"; ma=86400
❗ 常见问题提示
- 如果你配置了多个 tunnel,可以指定要运行的 tunnel,比如编辑
/etc/default/cloudflared,或手动创建一个 service 文件(进阶使用)。 - 如果你使用
--config ~/.cloudflared/config.yml,确保cloudflared安装路径和 config 路径匹配