Solving the Dynamic IP Dilemma: Raspberry Pi, BT Broadband, and GoDaddy DDNS

Solving the Dynamic IP Dilemma: Raspberry Pi, BT Broadband, and GoDaddy DDNS

When hosting a Ghost blog on a Raspberry Pi at home, the goal is simple: ensure the world can always find your server.

In a corporate environment, you typically have a static IP address. In a home lab—specifically one running on BT Broadband—you are at the mercy of a dynamic IP. Every time your Hub restarts or BT refreshes your lease, your public IP address changes, effectively "breaking" the link between your domain name and your Pi.

This post walks through automating the update of your GoDaddy DNS records using a simple Bash script and the GoDaddy API to ensure your blog stays online, no matter how many times your IP changes.


The Scenario

I am running a Ghost instance on a Raspberry Pi 5. My domain, ytrewq.co.uk, is managed by GoDaddy. Because BT Broadband assigns a dynamic IP, my DNS "A" record becomes outdated every few weeks (or days).

To solve this, I needed a way for my Raspberry Pi to:

  • Identify its own public IP address.
  • Check if that IP matches the current record on GoDaddy.
  • If they differ, push an update to GoDaddy automatically.

Automation turns a manual networking headache into a silent, background process.


Why use an API instead of a DDNS Service?

There are many third-party Dynamic DNS services (like No-IP or DuckDNS). However, if you already own a domain through a provider like GoDaddy, using their Production API allows you to keep your root domain (yourdomain.com) updated directly without needing a middleman or a "branded" subdomain.


The Solution: A Lightweight Bash Script

The following script uses curl to communicate with GoDaddy. It fetches your current public IP via ipify.org and compares it to the value held in your DNS settings.

#!/bin/bash

# Configuration
KEY="your_godaddy_api_key"
SECRET="your_godaddy_api_secret"
DOMAIN="ytrewq.co.uk"
TYPE="A"
NAME="@" 

# Get current public IP
CURRENT_IP=$(curl -s https://api.ipify.org)

# Get current IP registered at GoDaddy
GD_IP=$(curl -s -X GET "https://api.godaddy.com/v1/domains/$DOMAIN/records/$TYPE/$NAME" \
-H "Authorization: sso-key $KEY:$SECRET" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")

# Update GoDaddy if the IPs do not match
if [ "$CURRENT_IP" != "$GD_IP" ]; then
  echo "IP changed to $CURRENT_IP. Updating GoDaddy..."
  curl -s -X PUT "https://api.godaddy.com/v1/domains/$DOMAIN/records/$TYPE/$NAME" \
  -H "Authorization: sso-key $KEY:$SECRET" \
  -H "Content-Type: application/json" \
  -d "[{\"data\":\"$CURRENT_IP\"}]"
else
  echo "IP remains $CURRENT_IP. No update required."
fi

Implementation Steps

  1. API Credentials: Obtain a Production Key and Secret from the GoDaddy Developer Portal.
  2. Script Creation: Save the script to your Pi (e.g., /home/admin/godaddy-ddns.sh) and make it executable with chmod +x.
  3. Automation: Add the script to your crontab to run every 15 minutes. This ensures that even if BT triggers an IP change, your downtime is limited to a maximum of 15 minutes.
*/15 * * * * /bin/bash /home/admin/godaddy-ddns.sh >> /home/admin/ddns.log 2>&1

The Critical Piece: Port Forwarding

Updating the DNS record is only half the battle. Because the Raspberry Pi sits behind a BT Smart Hub, traffic hitting your public IP needs to know where to go. You must ensure your router is configured to forward the following:

Port Protocol Reason
80 HTTP Required for Let's Encrypt SSL renewals.
443 HTTPS The secure port your visitors will use to read the blog.

Final Thoughts

Self-hosting on a home connection like BT Broadband introduces unique challenges, but they are all solvable with a bit of automation. By leveraging the GoDaddy API and a Raspberry Pi, you can maintain a professional-grade hosting environment without the monthly cost of a static business IP.

Now, every 15 minutes, my Pi checks its "address" and tells the world where it moved. Simple, effective, and completely automated.