使用cloudflare在无固定ip的ubuntu系统做动态ddns解析
sudo -s
apt update
wget cloudflared deb
dpkg -i cloudflared.deb
cloudflared tunnel login
cloudflared tunnel create my-tunnel
cloudflared tunnel route dns my-tunnel b.你的域名.com
nano /etc/cloudflared/config.yml
cloudflared service install
systemctl enable --now cloudflared
每一行做一下注解
切换到 root 身份(之后所有命令都不用再加 sudo)
sudo -s
更新 APT 软件包索引(好习惯,防止装软件时报错)
apt update
下载最新版 cloudflared(AMD64 / x86_64)
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
安装 cloudflared
dpkg -i cloudflared-linux-amd64.deb
登录 Cloudflare,授权 你的域名.date
会输出一个 URL → 浏览器打开 → 登录 → 勾选 你的域名.com
cloudflared tunnel login
创建一个 Tunnel(名字叫 my-tunnel)可以起一个任意名称
成功后会出现 Tunnel UUID 和 credentials JSON 路径
cloudflared tunnel create my-tunnel
在 Cloudflare DNS 中自动添加 CNAME:
b.你的域名.com → .cfargotunnel.com
cloudflared tunnel route dns my-tunnel b.你的域名.com
编辑 Tunnel 配置文件(最重要的一步)
nano /etc/cloudflared/config.yml
-----------------------------------------------------------
tunnel: <Tunnel-UUID>
credentials-file: /root/.cloudflared/<Tunnel-UUID>.json
ingress:
- hostname: b.你的域名.com
service: http://localhost:80
- service: http_status:404
-----------------------------------------------------------
把 cloudflared 安装成 systemd 服务
cloudflared service install
设置开机自启并立即启动
systemctl enable --now cloudflared
查看运行状态(确认 active (running))
systemctl status cloudflared