先前做法#
先前, 我们是通过脚本来和 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 绑定#
なぜなら 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 パス匹配


