Dynamic IP using Cloudflare

Dynamic IP using Cloudflare

I previously posted an article about updating your DNS with your dynamic IP using paid service noip.com. I recently found out that you can do the same for free using Cloudflare.

Assumptions

  1. Registered an account with Cloudflare.
  2. Domain configured and active in Cloudflare. If not, read my post on how to configure one.
  3. Installed curl and jq.

Copy the content below into update.sh.

#!/bin/bash
json='Content-Type: application/json'
email='YOUR_EMAIL_HERE'
api_key='YOUR_GLOBAL_API_KEY_HERE'
zone_id='YOUR_ZONE_ID_HERE'
domain='www1.oofnivek.com'
dns_id=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=A&name=$domain" -H "X-Auth-Email: $email" -H "X-Auth-Key: $api_key" -H "$json"|jq -r .result[0].id)
#echo -n $dns_id
ip=$(curl checkip.amazonaws.com)
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$dns_id" -H "X-Auth-Email: $email" -H "X-Auth-Key: $api_key" -H "$json" \
--data '{"type":"A","name":"'$domain'","content":"'$ip'","ttl":1,"proxied":true}'
dynamic-ip-using-cloudflare
Create a sub domain for you to update dynamically
dynamic-ip-using-cloudflare
This is where you can get your global API key
dynamic-ip-using-cloudflare
Once clicked [View], your API key will be shown
dynamic-ip-using-cloudflare
You can get your Zone ID here

The API I used can be found here

List DNS Records

Update DNS Record