This post details my switch over to using Powershell and Cloudflare to update a DNS record to a server's current IP. This effectively emulates dyndns for this host - except it's free.
There are a load of other options out there, which even include some simple-but-quite-clunky apps for domain registrars like NameCheap; but installing third party software is not the route I want to take.
I previously had my target domain (let's call it targetdomain.com) hosted on a Linux box, and used SSH to update the DNS settings via a Windows server. This worked well for three years without a blip - but was clunky. I was using a scheduled task to start a bat file, which then ran Putty to run the shell script...to update a config on a server which was only hosting the domain to serve this purpose.
Although the scheduler>bat>shell tasks have been running well for years, it's time to simplify!
I've been using Cloudflare for years, and set aside time to write a script to use their service for this purpose. As it turns out, people have done this for years - so I've taken one off the shelf.
To do this, I copied the file into the all users directory (check $Env:PSModulePath if it's unknown).
The default public path for Powershell modules is C:\Program Files\WindowsPowerShell\Modules\[Module Name]\[Module files]
You can then import the module and check it's available
PS cd C:\Program Files\WindowsPowerShell\Modules\CloudFlareDynamicDns PS Import-Module .\CloudFlareDynamicDns PS Get-Module
The module is now imported
Setting up our task
I'm using task scheduler for this, as it's straight forward and easy to use. To test this, I simply ran the command on Powershell directly, which works. After, I switched it to calling it from a file and added some logging.
Let's get the script set up with some basics (including run when not logged on)
Something like every hour seems appropriate
I'm cheating on the action here, but it works fine for testing
At the current time, the two things on my mind are:
- There's no failure notifications (this feature is easily added however)
- The Cloudflare API requires use of your full account key. It's very surprising you can't create per-site keys, but it looks like this is in the works and expected at some point in 2019
- Cloudflare API Help: https://api.cloudflare.com/
- The module author's post: https://blog.netnerds.net/2015/12/use-powershell-and-cloudflare-api-v4-to-dynamically-update-cloudflare-dns-to-your-external-ip/