├── cloudflare-api.sh └── readme.md /cloudflare-api.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | # Docker: https://hub.docker.com/u/ellerbrock 8 | # Quay: https://quay.io/user/ellerbrock 9 | 10 | # Required Parameter 11 | CF_EMAIL="" 12 | CF_TOKEN="" 13 | CF_ZONE_NAME="" 14 | CF_DOMAIN_NAME="" 15 | 16 | # Optional Parameter 17 | EXTERNAL_IP=$(curl -s https://api.ipify.org) 18 | 19 | # we get them automatically for you 20 | CF_ZONEID="" 21 | CF_DOMAINID="" 22 | 23 | function getZoneID() { 24 | CF_ZONEID=$(curl -s \ 25 | -X GET "https://api.cloudflare.com/client/v4/zones?name=${CF_ZONE_NAME}" \ 26 | -H "X-Auth-Email: ${CF_EMAIL}" \ 27 | -H "X-Auth-Key: ${CF_TOKEN}" \ 28 | -H "Content-Type: application/json" | \ 29 | jq -r .result[0].id) 30 | } 31 | 32 | function getDomainID() { 33 | CF_DOMAINID=$(curl -s \ 34 | -X GET "https://api.cloudflare.com/client/v4/zones/${CF_ZONEID}/dns_records?name=${CF_DOMAIN_NAME}" \ 35 | -H "X-Auth-Email: ${CF_EMAIL}" \ 36 | -H "X-Auth-Key: ${CF_TOKEN}" \ 37 | -H "Content-Type: application/json" | \ 38 | jq -r .result[0].id) 39 | } 40 | 41 | function updateDomain() { 42 | curl -s \ 43 | -X PUT "https://api.cloudflare.com/client/v4/zones/${CF_ZONEID}/dns_records/${CF_DOMAINID}" \ 44 | -H "X-Auth-Email: ${CF_EMAIL}" \ 45 | -H "X-Auth-Key: ${CF_TOKEN}" \ 46 | -H "Content-Type: application/json" \ 47 | --data '{"type":"A","name":"'${CF_DOMAIN_NAME}'","content":"'${EXTERNAL_IP}'","ttl":1,"proxied":false}' 48 | } 49 | 50 | getZoneID 51 | getDomainID 52 | updateDomain 53 | 54 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Cloudflare Dynamic DNS Updater 2 | 3 | _Simple Bash Script to update your Cloudflare DNS._ 4 | 5 | This Script is also as Docker Container available here: 6 | 7 | - Docker Hub: [ellerbrock/alpine-cloudflare-dyndns](https://hub.docker.com/r/ellerbrock/alpine-cloudflare-dyndns/) 8 | - Quay: [ellerbrock/alpine-cloudflare-dyndns](https://quay.io/repository/ellerbrock/alpine-cloudflare-dyndns) 9 | 10 | ## Parameter 11 | 12 | - `EXTERNAL_IP`: optional, if not set it uses the current external ip addr 13 | - `CF_EMAIL`: required, your cloudflare login email 14 | - `CF_TOKEN`: required, your cloudflare api key (you can find it under [Settings](https://www.cloudflare.com/a/account/my-account) -> `API Key` -> `Global API Key`) 15 | - `CF_ZONE_NAME` required, your root domain name (eg. example.tld) 16 | - `CF_DOMAIN_NAME` required, your domain or subdomain name you want to update (eg. subdomain.example.tld) 17 | 18 | 19 | ## Cloudflare Script 20 | 21 | ```bash 22 | #!/usr/bin/env sh 23 | 24 | # Developer: Maik Ellerbrock 25 | # 26 | # GitHub: https://github.com/ellerbrock 27 | # Twitter: https://twitter.com/frapsoft 28 | # Docker: https://hub.docker.com/u/ellerbrock 29 | # Quay: https://quay.io/user/ellerbrock 30 | 31 | # Required Parameter 32 | CF_EMAIL="" 33 | CF_TOKEN="" 34 | CF_ZONE_NAME="" 35 | CF_DOMAIN_NAME="" 36 | 37 | # Optional Parameter 38 | EXTERNAL_IP=$(curl -s https://api.ipify.org) 39 | 40 | # we get them automatically for you 41 | CF_ZONEID="" 42 | CF_DOMAINID="" 43 | 44 | function getZoneID() { 45 | CF_ZONEID=$(curl -s \ 46 | -X GET "https://api.cloudflare.com/client/v4/zones?name=${CF_ZONE_NAME}" \ 47 | -H "X-Auth-Email: ${CF_EMAIL}" \ 48 | -H "X-Auth-Key: ${CF_TOKEN}" \ 49 | -H "Content-Type: application/json" | \ 50 | jq -r .result[0].id) 51 | } 52 | 53 | function getDomainID() { 54 | CF_DOMAINID=$(curl -s \ 55 | -X GET "https://api.cloudflare.com/client/v4/zones/${CF_ZONEID}/dns_records?name=${CF_DOMAIN_NAME}" \ 56 | -H "X-Auth-Email: ${CF_EMAIL}" \ 57 | -H "X-Auth-Key: ${CF_TOKEN}" \ 58 | -H "Content-Type: application/json" | \ 59 | jq -r .result[0].id) 60 | } 61 | 62 | function updateDomain() { 63 | curl -s \ 64 | -X PUT "https://api.cloudflare.com/client/v4/zones/${CF_ZONEID}/dns_records/${CF_DOMAINID}" \ 65 | -H "X-Auth-Email: ${CF_EMAIL}" \ 66 | -H "X-Auth-Key: ${CF_TOKEN}" \ 67 | -H "Content-Type: application/json" \ 68 | --data '{"type":"A","name":"'${CF_DOMAIN_NAME}'","content":"'${EXTERNAL_IP}'","ttl":1,"proxied":false}' 69 | } 70 | 71 | getZoneID 72 | getDomainID 73 | updateDomain 74 | ``` 75 | 76 | ## Contact / Social Media 77 | 78 | _Get the latest News about Web Development, Open Source, Tooling, Server & Security_ 79 | 80 | [![Github](https://github.frapsoft.com/social/github.png)](https://github.com/ellerbrock/)[![Docker](https://github.frapsoft.com/social/docker.png)](https://hub.docker.com/u/ellerbrock/)[![npm](https://github.frapsoft.com/social/npm.png)](https://www.npmjs.com/~ellerbrock)[![Twitter](https://github.frapsoft.com/social/twitter.png)](https://twitter.com/frapsoft/)[![Facebook](https://github.frapsoft.com/social/facebook.png)](https://www.facebook.com/frapsoft/)[![Google+](https://github.frapsoft.com/social/google-plus.png)](https://plus.google.com/116540931335841862774)[![Gitter](https://github.frapsoft.com/social/gitter.png)](https://gitter.im/frapsoft/frapsoft/) 81 | --------------------------------------------------------------------------------