Skip to content

Instantly share code, notes, and snippets.

@Realiserad
Last active August 16, 2023 13:52
Show Gist options
  • Select an option

  • Save Realiserad/135eadaed57deeb71a792ed0855c057a to your computer and use it in GitHub Desktop.

Select an option

Save Realiserad/135eadaed57deeb71a792ed0855c057a to your computer and use it in GitHub Desktop.
Dynamic DNS for Cloudflare
#!/bin/sh
# Get the ID for the DNS zone from the Cloudflare Dashboard:
# https://dash.cloudflare.com
DNS_ZONE=""
# To get the ID for the DNS record, do this:
# go install github.com/cloudflare/cloudflare-go/cmd/flarectl@latest
# fish_add_path "/home/(whoami)/go/bin"
# export CF_API_EMAIL=put your Cloudflare email here
# export CF_API_KEY=put your Global API Key here
# flarectl dns list --zone example.com --type A
DNS_RECORD=""
# Put your Cloudflare email and Global API Key here
EMAIL_ADDRESS=""
AUTH_KEY=""
# Put your domain name here, e.g. example.com
DNS_RECORD_NAME=""
CURRENT_IP_ADDRESS=$(curl icanhazip.com)
DATA="{\"type\":\"A\",\"name\":\"$DNS_RECORD_NAME\",\"content\":\"$CURRENT_IP_ADDRESS\"}"
curl -X PUT "https://api.cloudflare.com/client/v4/zones/${DNS_ZONE}/dns_records/${DNS_RECORD}" \
-H "X-Auth-Email:${EMAIL_ADDRESS}" \
-H "X-Auth-Key:${AUTH_KEY}" \
-H "Content-Type:application/json" \
--data "$DATA"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment