Created
December 17, 2019 18:06
-
-
Save xiamaz/cfff64e117ee9a707ef03677aaf79148 to your computer and use it in GitHub Desktop.
Cloudflare dynamic dns (dyndns) update script
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
[Unit] | |
Description=Update Cloudflare IP periodically. | |
[Service] | |
Type=oneshot | |
ExecStart=/usr/local/bin/cloudflare.sh |
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/sh | |
# Get Token with DNS EDIT Permission for needed zone. This can also be limited to the domain. | |
TOKEN="CLOUDFLARE API TOKEN" | |
ZONE="ZONE ID" | |
RECORD="RECORD ID" | |
DOMAIN="example.com" | |
# Get current IP | |
IPADDR=$(curl -s -4 ifconfig.me) | |
echo "Updating IP to $IPADDR" | |
## Use the commented part to get initial RECORD ID after creating the needed A entry in cloudflare. | |
# curl -X GET "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records?type=A&name=$DOMAIN&page=1&per_page=20&order=type&direction=desc&match=all" \ | |
# -H "Authorization: Bearer $TOKEN" \ | |
# -H "Content-Type: application/json" | |
curl -X PUT "https://api.cloudflare.com/client/v4/zones/$ZONE/dns_records/$RECORD" \ | |
-H "Authorization: Bearer $TOKEN" \ | |
-H "Content-Type: application/json" \ | |
--data "{\"type\":\"A\",\"name\":\"$DOMAIN\",\"content\":\"$IPADDR\",\"ttl\":1,\"proxied\":false}" |
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
[Unit] | |
Description=Update cloudflare IP periodically. | |
[Timer] | |
OnActiveSec=1min | |
OnUnitActiveSec=15min | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment