Last active
March 1, 2023 06:51
-
-
Save BrianMitchL/987ec33cabb81f176644b53810dd0bdc to your computer and use it in GitHub Desktop.
A bash script to update an A record for a domain in Cloudflare to be the value of the current IP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
zone_id= | |
# needs DNS read and write access | |
api_key= | |
# must also be in the given zone | |
record_name=example.com | |
ip=$(curl -s -X GET https://checkip.amazonaws.com) | |
record_id=$(curl -X GET "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records?type=A&name=$record_name" \ | |
-H "Authorization: Bearer $api_key" \ | |
-H "Content-Type:application/json" | jq -r '{"result"}[] | .[0] | .id') | |
curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_id/dns_records/$record_id" \ | |
-H "Authorization: Bearer $api_key" \ | |
-H "Content-Type:application/json" \ | |
--data "{\"type\":\"A\",\"name\":\"$record_name\",\"content\":\"$ip\",\"ttl\":1,\"proxied\":false}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment