dynamic dns update behind NAT using DigitalOcean DNS - kept simple, stupid.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

do-dyndns.sh 885B

123456789101112131415161718192021
  1. #!/bin/bash
  2. DOMAIN=${1}
  3. RECORD=${2}
  4. API_TOKEN=${3}
  5. [[ ! -z $DOMAIN ]] || exit 1;
  6. [[ ! -z $RECORD ]] || exit 1;
  7. [[ ! -z $API_TOKEN ]] || exit 1;
  8. IPV4=$(curl -s https://ip4.seeip.org)
  9. IPV6=$(curl -s https://ip6.seeip.org)
  10. [[ $IPV4 =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] || exit 1;
  11. # TODO: validate ipv6 response
  12. ID_IPV4=$(doctl -t ${API_TOKEN} compute domain records list --no-header --format ID,Type,Name ${DOMAIN} | grep ${RECORD} | grep " A " | cut -d' ' -f 1)
  13. ID_IPV6=$(doctl -t ${API_TOKEN} compute domain records list --no-header --format ID,Type,Name ${DOMAIN} | grep ${RECORD} | grep " AAAA " | cut -d' ' -f 1)
  14. doctl -t ${API_TOKEN} compute domain records update ${DOMAIN} --record-id ${ID_IPV4} --record-data ${IPV4} --record-ttl 60
  15. doctl -t ${API_TOKEN} compute domain records update ${DOMAIN} --record-id ${ID_IPV6} --record-data ${IPV6} --record-ttl 60