How to update IP address on Cloudflare
Hosting your services from home? But ISP is providing Dynamic IP Address?
In my scenario, I’ll be using a Synology’s Task Scheduler and Cloudflare.
- You’ll need to get all the details for the following variables
#Email associated with your Cloudflare account
EMAIL=""
#Global API Key
KEY=""
#Unique ID provided by Cloudflare
ZONE_ID=""
-
To get your
KEY
, go to your Cloudflare Profile > API Tokens and copy your Global API Key -
To get your
ZONE_ID
, go to your domain Overview, on the left panel you’ll see the API Zone ID, copy that. -
Put them all together and you get something like this:
#Email associated with your Cloudflare account
EMAIL="admin@example.com"
#Global API Key
KEY="xxxxxxxx"
#Unique ID provided by Cloudflare
ZONE_ID="xxxxxxxx"
#Record type
TYPE="A"
#Domain or Subdomain
NAME="example.com"
#Get IP Address
CONTENT="`curl https://ifconfig.co`"
#Enable Cloudflare proxy
PROXIED="true"
#In seconds, use 1 for automatic
TTL="1"
#The Code
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/dns_records/" /
-H "X-Auth-Email: $EMAIL" /
-H "X-Auth-Key: $KEY" /
-H "Content-Type: application/json" /
--data '{"type":"'"$TYPE"'","name":"'"$NAME"'","content":"'"$CONTENT"'","proxied":'"$PROXIED"',"ttl":'"$TTL"'}'
- Create a Task Scheduler and drop this script there.
- Buy me a drink on ko-fi :)
And that’s how you update Cloudflare with a Dynamic IP Address.