Skip to content

Instantly share code, notes, and snippets.

@Antti
Last active January 26, 2016 13:32
Show Gist options
  • Save Antti/7be08573a4381ebe259e to your computer and use it in GitHub Desktop.
Save Antti/7be08573a4381ebe259e to your computer and use it in GitHub Desktop.
cloudflare_auto_update_ip.sh
# Cloudflare automatic IP updating script.
# Usage instructions:
#
# 1. Get the cloud flare API key: https://www.cloudflare.com/a/account/my-account
# 2. Set some env variables:
# $ export [email protected]
# $ export CLOUDFLARE_API_KEY=your_api_key
# 3. Get your zone id:
# $ curl -X GET -H "Content-Type: application/json" -H "X-Auth-Key: ${CLOUDFLARE_API_KEY}" -H "X-Auth-Email:${CLOUDFLARE_EMAIL}" https://api.cloudflare.com/client/v4/zones
# 4. Get your record id:
# $ curl -H "Content-Type: application/json" -H "X-Auth-Key: ${CLOUDFLARE_API_KEY}" -H "X-Auth-Email:${CLOUDFLARE_EMAIL}" https://api.cloudflare.com/client/v4/zones/${YOUR_ZONE_ID}/dns_records
IP=$(curl -s http://ipecho.net/plain) && curl --data "{\"content\": \"$IP\"}" -X PATCH -H "Content-Type: application/json" -H "X-Auth-Key: ${CLOUDFLARE_API_KEY}" -H "X-Auth-Email:${CLOUDFLARE_EMAIL}" https://api.cloudflare.com/client/v4/zones/:zone_id/dns_records/:record_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment