Overview
Dynamic DNS (DDNS) updates DNS when your ISP assigns a new public IP. DigitalOcean DNS exposes a REST API to modify A records on your domain.
A small script compares the current public IP with the record value and PATCHes the record only when it differs.
Implementation
Create a personal access token with write scope. Note your domain name and record ID from the control panel or API. Schedule a script every 5–15 minutes via cron or Task Scheduler.
Fetch public IP from a reliable endpoint such as https://api.ipify.org. Use HTTPS and store the token in environment variables, not source code.
When implementing guidance from Digital Ocean Dynamic DNS, start in a controlled environment that mirrors production versions of operating systems, runtimes, and network policies. Capture a baseline before changes: export configs, snapshot VMs, or tag releases in source control so rollback stays straightforward if behavior regresses.
Document prerequisites, expected outcomes, and verification steps in a short runbook. Automated checks—smoke tests, health endpoints, or query validations—catch regressions early when platforms receive patches. Security belongs in every workflow: apply least privilege, rotate secrets, and review audit logs after deployment.
If results differ across machines, compare environment variables, permission models, time zones, and regional settings. Intermittent issues often trace to caching layers, stale DNS, or duplicated services bound to the same port.
Example
#!/bin/bash
TOKEN="$DO_TOKEN"
DOMAIN="example.com"
RECORD_ID="12345678"
IP=$(curl -s https://api.ipify.org)
curl -s -X PUT "https://api.digitalocean.com/v2/domains/$DOMAIN/records/$RECORD_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"data\":\"$IP\"}"
Tips
- Use low TTL (300s) during migration, higher TTL when stable.
- Restrict API token to DNS scope only.
- Log failures; alert if IP unchanged but site unreachable.
- Consider IPv6 AAAA records if your ISP provides them.
- Re-verify after reboots, certificate renewals, or failover exercises.
- Align monitoring and alerts with the failure modes described in this guide.
- Keep vendor documentation links handy for breaking changes between versions.
- Pair automation with a manual spot check during initial production rollout.