Dynamic DNS bash shell script for IPv6 prefix using token or DHCPv6 for Linux
A bash script to update your preferred Dynamic DNS service with dynamic IPv6 prefix. There are two versions of this script, one with IPv6 token and one with DHCPv6. If you use your router to set a fixed suffix then you can use the DHCPv6 version or if you use IPv6 token to set a suffix then use the token version.
First step is to create a text file which will contain the IPv6 address to compare with the new one. Run these commands to automatically create the file with a 0 in it.
If you choose to manually create the file then first create a blank file storedipaddress.txt and save it in /root/ddns-ipv6-address.txt, now open the file and type 0 and save and close the file. For some reason the storedipaddress.txt should not be empty for comparison this is why I had to type zero and save the file. Give the permissions 0777 to storedipaddress.txt so the script can write to it.
If you use token to set your IPv6 suffix:
Second step:
Now create a new file ddns-updater-hourly and save it in /etc/cron.hourly/ddns-updater-hourly (file name should not have any extension) and chmod 0755 for permission.
Example suffix used in this script 71c6:b34f:8e2a:54f5
Change the section "# Your DDNS update command goes here" with the command you are given by your DDNS provider such as Cloudflare.
/etc/cron.hourly/ddns-updater-hourly file content
If you use DHCPv6 to set your IPv6 suffix:
If you use your router to set a static suffix using DHCPv6 then use this script since there is no need to use a token.
First step:
It is the same as above to create a text file to store the IPv6 address. Follow the command above or manually create a text file in the correct location.
Second step:
/etc/cron.hourly/ddns-updater-hourly file content
Now edit the variables with your own values and save the file and it should run every hour to update the DDNS server. You can also save the file somewhere else and create your own cron job to your desired schedule.
Let me know if you have any comments or if there is any error in this guide.