Use Cloudflare as Dynamic DNS

I would like to share how I use Cloudflare as Dynamic DNS. I am using Dynamic DNS service from No-IP for three years until a colleague of mine mentioned about Cloudflare’s really fast global DNS. Initially, I thought that Cloudflare was just a CDN and an Internet company that protects websites from Distributed Denial-of-Service (DDoS) attack, upon further investigation I found out that Cloudflare also provides a DNS service with a REST-API for you to update your DNS records.

I migrated most of my domain to CloudFlare DNS and then uses their API to update my domain’s DNS records once my ISP changed the IP address.

To know my router’s IP address I use the service of You may use other provider or other technique to know your router’s public IP address.

Source code available at


IP=$(curl -s "")
echo "THIS IS IP $IP"
touch dynip.txt
OLD_IP=$(cat dynip.txt)
echo "OLD IP: $OLD_IP"

curl -X PUT "$1/dns_records/$2" \
-H "X-Auth-Email: [email protected]" -H "X-Auth-Key: YOUR_CLOUDFLARE_API_KEY" \
-H "Content-Type: application/json" \
--data "{\"type\":\"A\",\"name\":\"$4\",\"content\":\"$3\",\"proxied\":$5}"

if [ "$IP" != "$OLD_IP" ]; then
    echo "Changing IP"
    echo $IP > dynip.txt
    curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "true"
    curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "true"
    curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "false"
    #curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "true"
    #curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "true"
    #curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "true"
    #curlUpdate "ZONE_ID" "ID_OF_DNS_RECORD" "$IP" "" "true"

You can then setup your CRON to run the script on a specified interval or schedule.


Cloudflare’s DNS REST API is owned by Cloudflare and subject to Cloudflare’s terms and conditions.