Insights into building a solid I.T. foundation in the mid-size business world.

Scripting a dynamic IP address change notifier

This blog is hosted on a small, Ubuntu Linux-based server in my home. Given that we have a typical, residential Internet connection, our router’s IP address is subject to change at any time (this can make it challenging to provide you, the reader, reliable access to blog.chrisjscott.net).

My domain was, until recently, managed by Google’s domain services – one of the great parts about that service was that it provided a way to “monitor” my home’s IP address and automatically update the associated DNS record whenever the IP address changed – a process known as Dynamic DNS (DDNS). Unfortunately, Google – in typical Google fashion – recently killed their domain management service and moved me to Squarespace.

Squarespace doesn’t offer DDNS service, so I now have to manage this on my own. While I could utilize a third-party service to do this, most require a subscription to manage a permanent domain (rather then just a subdomain of the service provider). Given that I’m lucky enough that my home IP address rarely changes, I decided to forego yet another subscription cost and, instead, to whip up a shell script that detects when my IP address changes and to send me a text to let me know when I need to update my DNS’ ‘A’ record.

It’s pretty simple really – I’m taking advantage of two external tools here:

  • https://www.ipify.org/ is a site that does nothing but display your current, external-facing IP address in plain text
  • https://textbelt.com/ is an amazing, free service that enables you to send text messages to a specified phone number via shell script (the developer, Ian Webster, is very generous with his time and I encourage you to throw him a few dollars to support his efforts)

With those two things in-hand, here’s the script:

Obviously, replace the blue text with your own values (you can generate you own Textbelt key by visiting their website)…

With this in-hand, I configure this to run on my Linux server as a cronjob every six hours and, should the IP address change, I get a text message notifying me that it’s time to visit Squarespace and update the record:


You’ll note that I wrote this to ensure I wasn’t passing any URLs or IP addresses through Textbelt (since they don’t allow it). But then I realized that, during testing, when I did try to pass a URL, I got a warning back that let me know that, if I wanted to pass URLs, I could request that my API key be added to a whitelist!

Once I realized that (and got the exception), I removed the search & replace line and added my DNS manager’s URL (punched through the is.gd URL shortener for brevity) to the notification so that I could get to it directly from the text message I receive!

Leave a Reply

Your email address will not be published. Required fields are marked *