Small script allowing to sync one's home IP records to Linode DNS.
Made initially to run periodically on an Ubiquiti Edge Router Lite.
If you're already familiar with this script, or don't care about the details you can run this to expedite the setup (it'll prompt you for your token and hostname):
curl -O https://raw.githubusercontent.com/zsimic/linode-ddns/main/install-linode-ddns.sh
sudo bash install-linode-ddns.sh
rm install-linode-ddns.sh
Here's a more detailed walk-through, if you're interested to see how the script works.
ssh to your router, then:
sudo curl -s -o/config/scripts/linode-ddns https://raw.githubusercontent.com/zsimic/linode-ddns/main/linode-ddns.py
sudo chmod 0755 /config/scripts/linode-ddns
The config /config/scripts/linode-ddns.json
will eventually look like this:
{
"records": "1234/records/4321",
"token": "...linode token..."
}
This script can help with creating that file, and check that everything works properly before we create a scheduled job to run it periodically.
First, we'll run the script with argument domains
in order to:
- have the script ask you for your token (and store it in
/config/scripts/linode-ddns.json
) - double-check that things work (linode REST API query to list your domains)
Let's run:
sudo /config/scripts/linode-ddns -i domains
This will ask you to paste in your token, and will show you your linode domains. If it works, next step is to add a reference to the linode DNS records to be updated.
If your domain is example.com
, and you want to make home.example.com
point to your home IP,
then you need to create an A
DNS record on linode
with hostname home
(put some IP address manually there just to get the record created).
Next, we check that the script can find that record by running:
sudo /config/scripts/linode-ddns -i home.example.com
This should show your record.
Note that the script can update several records at the same time, if you have say
home.domain1.com
and home.domain2.com
, this script can update them all...
If you would like to update several domains at once, omit the domain part as in:
sudo /config/scripts/linode-ddns -i home
Doing so will configure fetch a config that will update all hostnames home
on all your domains.
Once you see what you expect, either take the output and save it to /config/scripts/linode-ddns.json
,
or run this to have the script do that for you:
sudo /config/scripts/linode-ddns -i home.example.com --commit
All right, so now you should have an operational script that will update the IP when invoked without arguments. We can try it out:
sudo /config/scripts/linode-ddns
sudo cat /config/scripts/linode-ddns-ip.txt # Should show your IP!
# Should show one log message stating that IP was updated
tail /var/log/messages
# If we run it again, nothing should happen
sudo /config/scripts/linode-ddns
# Only one "IP updated" message still
tail /var/log/messages
For example every 30 minutes:
configure
set system task-scheduler task linode-ddns interval 30m
set system task-scheduler task linode-ddns executable path /config/scripts/linode-ddns
commit
save
To double-check that the task is getting triggered, you can do this:
# Force script to re-run by deleting the file where it remembers which IP it last saw
sudo rm /config/scripts/linode-ddns-ip.txt
# Wait 30 minutes (or whatever time you scheduled)
# You should see evidence that the script ran:
sudo cat /config/scripts/linode-ddns-ip.txt
# The logs should have a line saying: "... linode-ddns: Home IP updated to ..."
tail -f /var/log/messages