A customer wants their site to failover automatically to a backup server when the primary goes down. Their budget is roughly nothing — they don’t want to pay for AWS Route 53 health checks, Cloudflare load balancing, or a hosted multi-region DNS. cPanel doesn’t have DNS health checks. You can build something that works at a low TTL with external monitoring, but the constraints are real.
What’s happening
True DNS failover needs three things:
- A short TTL so resolvers refresh quickly when the record changes.
- A health check that runs continuously and detects when the primary is down.
- An automated record update when the health check fails.
Hosted DNS providers offer all three as a service (Route 53 health checks, Cloudflare load balancer, NS1 traffic management). cPanel provides only the DNS itself — no health checks, no automated failover.
For a budget DIY version:
- The TTL is yours to control. Set it to 60 in cPanel Zone Editor.
- The health check has to live somewhere else. An off-host VM, a free uptime service (UptimeRobot’s free tier polls every 5 minutes from one location), or a script on the cPanel host itself (problematic — if the host is down, the script doesn’t run).
- The update has to call cPanel’s API. A small script that polls the primary and
whmapi1 editzonerecordon failure.
What you give up vs hosted:
- Detection latency: a free check polls every 5 minutes; hosted DNS checks run every 30 seconds. Failover takes 5+ minutes vs 30 seconds.
- Multi-region check: hosted DNS checks from multiple geographies and consensus-votes. A single off-host VM checks from one place — false positives are more common.
- Automatic recovery: hosted DNS detects when the primary comes back and fails the record back. DIY has to add that logic explicitly.
How to verify
If you’ve built a DIY failover, test it by simulating primary failure:
# stop the primary's web service (in a test environment, of course)
ssh primary "systemctl stop apache2"
# wait the polling interval + propagation
sleep 360
# verify the record now points at the backup
dig +short example.com @1.1.1.1
If the record changed, the failover works. If not, the script didn’t fire or the API call failed.
Watch the script’s log:
tail -f /var/log/dns-failover.log
What to do
For a minimal DIY failover:
- Set TTL to 60 on the A record being failover’d. In cPanel Zone Editor, edit the record and set TTL = 60.
- Provision a small VM outside the cPanel host’s region. Any cheap VPS (1 GB RAM, 1 vCPU) works. This is the monitor.
- Write the monitor script on the VM:
#!/bin/bash
TOKEN="<api-token>"
HOST="cpanel-host.example.com"
ZONE="example.com"
NAME="example.com."
PRIMARY="192.0.2.10"
BACKUP="203.0.113.20"
CHECK_URL="https://example.com/health"
# Poll the primary
if curl -sf --max-time 5 --resolve example.com:443:$PRIMARY "$CHECK_URL" > /dev/null; then
TARGET=$PRIMARY
else
TARGET=$BACKUP
fi
# Get current record value
CURRENT=$(dig +short @ns1.example.com example.com)
# Update if different
if [ "$CURRENT" != "$TARGET" ]; then
LINE=$(curl -sk -H "Authorization: whm root:$TOKEN" \
"https://$HOST:2087/json-api/dumpzone?api.version=1&domain=$ZONE" \
| jq -r ".data.zone[].record[] | select(.name==\"$NAME\" and .type==\"A\") | .Line")
curl -sk -H "Authorization: whm root:$TOKEN" \
"https://$HOST:2087/json-api/editzonerecord?api.version=1&domain=$ZONE&Line=$LINE&name=$NAME&type=A&address=$TARGET&ttl=60"
echo "$(date) failover: $CURRENT -> $TARGET" >> /var/log/dns-failover.log
fi
- Run on a cron, every 1 to 5 minutes. Lower intervals = faster failover but more API calls.
- Test the failover in a controlled outage (overnight, with the customer aware). Confirm the record flips and clients pick up the new IP.
- Document the limitations. Single-region check, 5+ minute detection, no auto-recovery if you don’t code it.
When to stop and use a hosted service:
- If the customer needs sub-minute failover (mail server, e-commerce checkout flow).
- If the customer needs multi-region origin (the backup isn’t just a hot standby but a region-isolated copy).
- If you’re managing more than a few zones with failover — the DIY scripts multiply, and one of them eventually breaks.
Cloudflare’s load balancer starts at a modest monthly cost for basic health-check failover. Route 53 health checks plus failover routing add cents per check. For most setups, hosted is cheaper than the operational cost of running DIY scripts.
Stack Harbor evaluates budget-vs-hosted failover during architecture work in deployment management.