What is the name of the domain?
What is the error number?
No error. This is a tip.
What is the error message?
No error. This is a tip.
What is the issue you’re encountering
Easily do automatic dynamic DNs updates.
What steps have you taken to resolve the issue?
Wrote the following to a file and added it to my crontab:
ZONE_ID=‘****************’ # for your example.com
URL=“https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records”
API_TOKEN=‘**************’’ # for your account
function dnsUpdate {
SELECT=$(curl -s -X GET “$URL”
-H “Content-Type: application/json”
-H “Authorization: Bearer $API_TOKEN”
| sed “s:{"id":\n{"id":g” | grep “"name":"$1.”)
RECORD_ID=$(echo $SELECT | sed ‘s/^{“id”:“//;s/”,“name”.//')
OLD_IP=$(echo $SELECT | sed 's/.“content”:"([.0-9])./\1/’)
echo “$1 ($RECORD_ID) = $OLD_IP”
if [[ -n "$OLD_IP" && -n "$2" && "$OLD_IP" != "$2" ]] ; then
curl -s -X PUT "$URL/$RECORD_ID" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $API_TOKEN" \
--data "{\"type\":\"A\",\"name\":\"$1\",\"content\":\"$2\",\"ttl\":300}"
echo -e "\n\n$1.example.com ($RECORD_ID) IP address changed from $OLD_IP to $2"
fi
}
dnsUpdate myhostname $(curl -s api.ipify.org)
What feature, service or problem is this related to?
DNS records
What are the steps to reproduce the issue?
Searched the Internet for a simple solution. Found none.