Cron for Dynamic DNS Updating
I use my commercial host, Ionos, for websites, including creating subdomains for ones I’m hosting at home. However, I don’t pay for a static ip. I was using a Windows Scheduled Task to curl the necessary URLs to keep the IP updated, but I’m switching everything I can over to Linux, and a Pi.
Start by creating your .sh file and making it executable. I created dnsupdate.sh in my home dir on my Pi, and populated it with my curl calls. I did this via Nano. Then make it executable:
1 |
sudo chmod +x dnsupdate.sh |
Then I fired up cron by entering:
1 |
crontab -e |
It’s going to ask you for an editor on first use. I say, stick with Nano.
1 2 3 4 5 6 7 8 9 |
no crontab for root - using an empty one Select an editor. To change later, run 'select-editor'. 1. /bin/nano <---- easiest 2. /usr/bin/vim.tiny 3. /bin/ed Choose 1-3 [1]: 1 crontab: installing new crontab |
After this it will present you with a crontab file. Scroll to the bottom and enter:
1 |
0 * * * * /home/USERNAME/dnsupdate.sh |
This will run your sh file every hour at the top of the hour.
Save the file.
If you want to see what’s up with Cron, enter:
1 |
systemctl status cron |
If it’s running, it’ll show you the files – your sh file – in use by cron.