Add remove multiple IPv6 addresses on prefix change
A bash script to add and delete multiple IPv6 addresses on prefix change.
First step is to create a text file with "0000:0000:0000:0000" as text which will store the IPv6 prefix of your server. Create a file using this example.
If you choose to manually create the file then first create a blank file IPv6Prefix.txt and save it in /root/IPv6Prefix.txt, now open the file and type 0000:0000:0000:0000 and save and close the file. For some reason the IPv6Prefix.txt should not be empty for comparison this is why I had to type zero and save the file. Give the permissions 0777 to IPv6Prefix.txt so the script can write to it.
Now the second step is to create a text file containing all your IPv6 suffixes that you want to add to your server. For example
Now create a bash file to do all the processing. You need to create a schedule to periodically check the IPv6 prefix for change. Change the interface name (ens18) to the name of your interface.
The final step is to reset the file IPv6Prefix.txt on your computer startup or reboot. Create a crontab entry to reset the file on each reboot.
Let me know if you have any comments or if there is any error in this guide.