Skip to content

Instantly share code, notes, and snippets.

@davxiao
Created March 26, 2024 23:39
Show Gist options
  • Save davxiao/3ac85e3e16669f69afcb10c05cacc86e to your computer and use it in GitHub Desktop.
Save davxiao/3ac85e3e16669f69afcb10c05cacc86e to your computer and use it in GitHub Desktop.
#!/bin/sh
cloudflare_email='your sign-in email'
cloudflare_apikey='your api key'
cloudflare_dns_record='your dns record'
cloudflare_zone_id='your dns zone id on cloudflare'
cloudflare_dns_record_id='your dns record id under the zone'
data_string=$( jq -n \
--arg ip "$(curl --silent ipecho.net/plain)" \
--arg nm "$cloudflare_dns_record" \
--arg ty 'A' \
--arg co 'dns record' \
'{content: $ip, name: $nm, proxied: false, type: $ty, comment: $co, ttl: 3600}' )
curl --silent --request PUT \
--url "https://api.cloudflare.com/client/v4/zones/$cloudflare_zone_id/dns_records/$cloudflare_dns_record_id" \
--header 'Content-Type: application/json' \
--header "X-Auth-Email: $cloudflare_email" \
--header "X-Auth-Key: $cloudflare_apikey" \
--data "$data_string" \
| jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment