Question
Using the v2 API and my Home Computer to Automatically Update a Domain Name A Record (Like Dynamic DNS)
I want to have a script run automatically on my Mac at home, once an hour, to update the A record of a domain name which lives on DigitalOcean’s name servers.
I want the A record to be updated with whatever my external home IP address is (in effect, a dynamic DNS service so I can always get back to my home computer over the internet). My home computer sits behind a router supplied by my ISP.
I have been looking at the DigitalOcean API (v2) and using Terminal on my Mac I can successfully, manually, update the A record in question with the following command:
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer MY_API_ACCESS_TOKEN" -d '{"data":"IP_ADDRESS"}' "https://api.digitalocean.com/v2/domains/MY_DOMAIN/records/DOMAIN_ID_NUMBER"
What I’d like some help with, please, is how do I add to the above so that:
- My home external IP address gets ascertained when the script runs,
- Once ascertained, the IP address is automatically used (in place of ‘IP_ADDRESS’) in the above command, and,
- The command runs on its own, once an hour.
I’m quite new to all this so I’m sorry if I’m missing anything obvious.
Thanks, any help appreciated.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×