Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 14, 2022 12:13 pm GMT

Cloudflare DDNS on Linux

1. Generate token in My profile API Tokens Create Token with Zone.DNS permission for selected DNS zone.*

Note that it is not possible to select only one subdomain and token will have permission to change all DNS entries.

2. Use the following script to update DNS entry automatically on your server and save it as /usr/local/bin/ddns:

#!/bin/bash# Check for current external IPIP=`dig +short txt ch whoami.cloudflare @1.0.0.1| tr -d '"'`# Set Cloudflare APIURL="https://api.cloudflare.com/client/v4/zones/DNS_ZONE_ID/dns_records/DNS_ENTRY_ID"TOKEN="YOUR_TOKEN_HERE"NAME="DNS_ENTRY_NAME"# Connect to Cloudflarecf() {curl -X ${1} "${URL}" \     -H "Content-Type: application/json" \     -H "Authorization: Bearer ${TOKEN}" \      ${2} ${3}}# Get current DNS dataRESULT=$(cf GET)IP_CF=$(jq -r '.result.content' <<< ${RESULT})# Compare IPsif [ "$IP" = "$IP_CF" ]; then    echo "No change."else    RESULT=$(cf PUT --data "{\"type\":\"A\",\"name\":\"${NAME}\",\"content\":\"${IP}\"}")    echo "DNS updated."fi

3. Add script to crontab, so it will be executed every minute:

# crontab -e
* * * * * /usr/local/bin/ddns > /dev/null 2>&1

Original Link: https://dev.to/ordigital/cloudflare-ddns-on-linux-4p0d

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To