#!/bin/bash # ========================================================== # CONFIGURATION # ========================================================== # 1. Enter your Cloudflare credentials here: auth_token="" zone_id="" # 2. List all subdomains you want to update inside the parentheses. # Separate them with spaces. records_list=( "" # <-- You can easily add more later in quotation marks ) # ========================================================== # 1. Get your current Public IP from the internet (Only need to do this once) echo "--------------------------------------------------" echo "Checking current Public IP..." ip=$(curl -s -4 https://ifconfig.me) if [ -z "$ip" ]; then echo "Error: Could not find your public IP." exit 1 fi echo "Detected Public IP: $ip" echo "--------------------------------------------------" # 2. Loop through each record in our list for record_name in "${records_list[@]}"; do echo "Processing: $record_name" # A. Get the specific "Record ID" for this specific subdomain record_info=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=A&name=$record_name" \ -H "Authorization: Bearer $auth_token" \ -H "Content-Type: application/json") # Extract the ID record_identifier=$(echo "$record_info" | jq -r '{"result"}[] | .[0] | .id') if [ "$record_identifier" == "null" ] || [ -z "$record_identifier" ]; then echo " [!] Error: Could not find record ID for $record_name." echo " Make sure this record actually exists in your Cloudflare dashboard." echo "--------------------------------------------------" continue # Skip to the next domain in the list fi # B. Send the new IP to Cloudflare # 'proxied': false is maintained (Grey Cloud) for game/voice servers update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_identifier" \ -H "Authorization: Bearer $auth_token" \ -H "Content-Type: application/json" \ --data "{\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\",\"ttl\":120,\"proxied\":false}") # C. Check if it worked success=$(echo "$update" | jq -r '.success') if [ "$success" == "true" ]; then echo " [✓] SUCCESS: Updated to $ip" else echo " [X] FAILURE. Cloudflare response:" echo "$update" | jq .errors fi echo "--------------------------------------------------" done echo "All updates complete."