← All articles
DOC_001 · 29 Oct 2026 · 2 MIN READ
Automated DNS failover with a small Go daemon
How it works
For each configured record, the daemon checks the primary health URL on an interval. After a number of consecutive failures it looks at the secondary: if that one is healthy it moves the DNS record to the secondary IP, otherwise it raises an alert because there is nowhere to go.
How the daemon decides: check, fail over, restore
Configuration
Everything lives in one YAML file: the Cloudflare token and zone, the Discord webhook, the thresholds and the list of records to supervise.
cf_api_token: "your_cloudflare_token"
cf_zone_id: "your_zone_id"
discord_webhook_url: "https://discord.com/api/webhooks/xxx/yyy"
check_interval: "30s"
health_check_timeout: "5s"
failover_threshold: 3
secondary_alert_threshold: 5
stability_duration: "5m"
dry_run: false
records:
- name: "api"
cf_record_name: "api.example.com"
primary_ip: "1.2.3.4"
primary_health_url: "https://api.example.com/health"
secondary_ip: "5.6.7.8"
secondary_health_url: "https://api-secondary.example.com/health"curl -s -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
-H "Authorization: Bearer YOUR_TOKEN" | jq .success
# must return: trueDeploying
The daemon is compiled on the server and run as a systemd service.
go build -o dns-failover ./
sudo useradd -r -s /bin/false dns-failover
sudo cp dns-failover /opt/dns-failover/
sudo cp config.yaml /opt/dns-failover/config.yaml
sudo cp dns-failover.service /etc/systemd/system/
sudo systemctl enable --now dns-failover
journalctl -u dns-failover -f