Why you don’t need to pay for a DDNS provider

Due to the COVID-19 outbreak, I have been working from home more than usual.

After months of being isolated at home, I decided to spend few weeks working abroad. I have everything I needed, a mobile phone to create a WiFi hotspot and a Macbook Air. It should be enough for almost any working task but some workflow requires a bit more power than the laptop can offer.

Of course, I could get a cloud instance and run these heavy workflows there but having a desktop at home who wants to pay for these cloud instances? Also, the desktop is my main working machine and I was sure I would need to access it to get extra files I won't have on the laptop.

So I decided to leave all configured to access my main machine while working abroad. This machine was already configured to allow remote access but there was a problem, the dynamic IP from the internet provider may change at any time.

The most straightforward solution would have been to get a Dynamic DNS (DDNS) provider but I preferred to build my own solution for free!

I ended writing this small script to check my current IP and send me a message using Messages.app when it changes. The script is executed every hour, this way connecting to my home desktop was as easy as checking the current IP on the Messages app.

## !/bin/sh

CURRENT_IP=$(dig +short myip.opendns.com@resolver1.opendns.com)
LAST_IP=$(cat $FILE)

echo "$(date) - Current IP: $CURRENT_IP"

if [ "$CURRENT_IP" != "$LAST_IP" ]; then
  osascript -e "tell application \"Messages\" to send \"New home ip: $CURRENT_IP\" to buddy \"first.name@gmail.com\"" && \
    echo $CURRENT_IP > $FILE

You can also find me on Twitter if you’d like to follow my thoughts in real-time!

Related posts

Apr 21, '20

Install Apache Spark on macOS

2 min read