Dynamic DNS update from cron

We can use crontab to update our Dynamic DNS. It’s a nice feature and super easy. Who wants a whole application dedicated to telling a remote server your IP?

Create a script, not necessary, can do it right in crontab, but why? make a script. If you don’t have a scripts folder in your home directory make one. mkdir scripts I’m not here to teach you basic bash commands.

nano /home/username/scripts/update-dns.sh
 
Put the following in the script.
 
#!/bin/bash
curl https://your-registrar-will-give-you-this.com/update?host=@&domain=xxxxxx.com&password=xxxx
 
OR, I use this one now, but same concept (the q tells it to be quiet and the O tells it to full output to stdout (so we can kill the downloaded file by writing it to /dev/null in our crontab))
 
#!/bin/bash
wget --no-check-certificate -qO- https://your-registrar-will-give-you-this.com/update?host=@&domain=xxxxxx.com&password=xxxx
 
The script needs to be executable.
chmod  755 /home/username/scripts/update-dns.sh
 
Make sure that your xxxxx.com domain name has a dynamic listing for @ and that the password for updating it is still correct in the script. This is registrar dependent. Ask them how to enable dynamic DNS on their side and get the password.
 
 
Set it in to a cron job to run every hou. Crontab keeps track of your users cron jobs. They will run even if you aren’t logged in.
crontab -e
 
add at the bottom. This will run on the hour every hour. Some people update it every 15 minutes. I don’t. The last part of the call there, the > /dev/null 2>&1 tells the shell to send any output on stdout or stderror to nowhere-land. If you don’t do this, wget will download a file in your home directory called update every hour. You don’t want that, you want to update your IP and ignore that update file. So kill it with that redirect.
0 * * * * /home/username/scripts/update_dns.sh > /dev/null 2>&1

Leave a Reply

Your email address will not be published.