This Bash script automatically updates a Cloudflare DNS record with your current public IP addresses, including support for:
- IPv6
- Dual IPv4 addresses from two ISPs (ISP1 and ISP2)
It is intended for home servers or self-hosted services using Cloudflare for DNS and having multiple external IPs (e.g., from dual-WAN routers or multiple broadband providers).
- Supports both
A(IPv4) andAAAA(IPv6) records. - Supports two distinct IPv4 addresses (e.g., dual ISP environments).
- Works with dynamic IP addresses.
- Simple and easily customizable.
- A Cloudflare API token with DNS edit permissions.
- Pre-existing DNS records in Cloudflare (one AAAA and two A records).
curl,jq, andhostcommand-line tools installed.
Edit the script variables:
API_TOKEN="your_cloudflare_api_token"
zoneid="your_zone_id"
dnsrecord="your.full.domain.com"
dnsrecordid6="record_id_for_AAAA"
dnsrecordid4_isp1="record_id_for_ISP1_IPv4"
dnsrecordid4_isp2="record_id_for_ISP2_IPv4"Set IP information source URLs (optional):
IPV6_INFO_SOURCE="https://6.ipw.cn"
IPV4_INFO_SOURCE="http://myip.ipip.net"Update ISP keywords in the script (ISP1, ISP2) to match your actual provider labels (e.g., "China Telecom", "China Unicom").
Make the script executable and run:
chmod +x ddns-update.sh
./ddns-update.shYou can add it to a cron job for automatic updates:
crontab -e
# Run every 10 minutes
*/10 * * * * /path/to/ddns-update.sh- Do not share your API token or zone ID.
- Consider storing sensitive values in environment variables or a
.envfile and loading them in the script.
MIT License.