轻量级双 WAN DNS 故障转移控制器,支持基于 Huawei Cloud DNS 线路解析实现自动故障切换和恢复。
A lightweight dual-WAN DNS failover controller with Huawei Cloud DNS line-based routing support.
config.yaml 配置.envdocker pull zyuzone/ddns-failover:latest
例如:
WAN1 DDNS -> wan1.example.com
WAN2 DDNS -> wan2.example.com
正常情况下:
DNS Line 1 -> WAN1
DNS Line 2 -> WAN2
WAN2 故障:
DNS Line 1 -> WAN1
DNS Line 2 -> WAN1
WAN2 恢复并达到恢复阈值:
DNS Line 1 -> WAN1
DNS Line 2 -> WAN2
WAN1 同样支持自动切换到 WAN2。
运行配置统一存放在:
/config/config.yaml
示例:
huawei_cloud:
access_key: CHANGE_ME
secret_key: CHANGE_ME
region: cn-north-4
dns:
zone: example.com
target_fqdn: service.example.com
wan1_fqdn: wan1.example.com
wan2_fqdn: wan2.example.com
ttl: 60
auto_create_target_records: true
allow_non_global_ip: false
routes:
line1:
id: region_line_id
label: Line1
preferred_wan: wan1
line2:
id: default_view
label: Line2
preferred_wan: wan2
health_check:
port: 443
timeout: 3
interval: 10
ip_refresh_interval: 30
fail_threshold: 3
recover_threshold: 6
runtime:
dry_run: false
state_file: /config/state.json
logging:
file: /config/logs/ddns-failover.log
level: INFO
retention_days: 30
timezone: Asia/Shanghai
先创建配置目录:
mkdir -p /opt/Container/DDNS-Failover/logs
将 config.yaml 放到:
/opt/Container/DDNS-Failover/config.yaml
启动容器:
docker run -d \
--name ddns-failover \
--restart unless-stopped \
--network host \
-v /opt/Container/DDNS-Failover:/config \
zyuzone/ddns-failover:latest
查看日志:
docker logs -f ddns-failover
持久化日志:
tail -f /opt/Container/DDNS-Failover/logs/ddns-failover.log
services:
ddns-failover:
image: zyuzone/ddns-failover:latest
container_name: ddns-failover
restart: unless-stopped
network_mode: host
volumes:
- /opt/Container/DDNS-Failover:/config
DDNS-Failover 不仅检查 DDNS 是否存在,而是直接检测:
WAN1_PUBLIC_IP:PORT
WAN2_PUBLIC_IP:PORT
这样即使宽带断线后 DDNS 仍暂时保留旧公网 IP,也可以根据真实服务可达性触发故障转移。
推荐将容器部署在被监控网络之外,例如云服务器,以获得真实的外部网络检测结果。
每条 WAN 应拥有独立 DDNS:
wan1.example.com -> WAN1 Public IP
wan2.example.com -> WAN2 Public IP
DDNS 可以由:
负责维护。
DDNS-Failover 本身负责:
获取 WAN IP
↓
TCP 健康检测
↓
故障 / 恢复判断
↓
修改 Huawei Cloud DNS
默认日志:
/config/logs/ddns-failover.log
状态文件:
/config/state.json
支持日志轮转及历史日志自动清理。
不要将包含真实 Huawei Cloud AK/SK 的 config.yaml 上传到公开仓库或构建进 Docker 镜像。
建议:
GitHub:
https://github.com/zyuzone/ddns-failover
zyuzone/ddns-failover
Content type
Image
Digest
sha256:9ab1c28cf…
Size
87.9 MB
Last updated
14 days ago
docker pull zyuzone/ddns-failover