cat /etc/cron.d/freedns-watcher
PATH=/sbin:/usr/sbin:/bin:/usr/bin * * * * * root ipv6=$(ip a |grep -s -i -o '2001\:[a-f0-9\.:]*') && [ "$(nslookup -query=AAAA myhost.mooo.com ns1.afraid.org |grep -s -i -o '2001\:[a-f0-9\.:]*')" != "$ipv6" ] && curl -m 30 https://freedns.afraid.org/dynamic/update.php?bnJxM3kxMHRHF1p4B0NmSXJDfEFLc0NJOjEzMTEyNjv\&address=$ipv6 2>/dev/null |grep Updated && date >> /var/log/freedns.log &> /dev/null
* * * * *
5 stars - information for cron to "run it every minute" root
decide for yourself what uchetkom run ipv6=$(ip a |grep -s -i -o '2001\:[a-f0-9\.:]*')
We get from the exhaust ip teredo-address, it works like this: ip a |grep -s -i -o '2001\:[a-f0-9\.:]*' 2001:0:52ab:53b:2ab4:555e:23d0:1dc9
If the address is found, we put it in the $ ipv6 variable, if not found, it assigns faylitsya and further work on updating the AAAA record is not performed (after all, the typical reason for the lack of a teredo address is the lack of connection (IPv4) to the Internet, and there is really nothing to update ) [ "$(nslookup -query=AAAA myhost.mooo.com ns1.afraid.org |grep -s -i -o '2001\:[a-f0-9\.:]*')" != "$ipv6" ]
We are polling the server ns1.afraid.org for "what is the IP address you have there now recorded for my AAAA?" And compare it with what we currently configured miredo. If it matches, you don’t need to do anything, the script is interrupted. Why is their DNS server listed instead of system? To minimize the delay of notification of our script about a record change. On other DNS servers, the change will be with a long delay. It would have been possible not to check anything, but stupidly to hammer at the specified URL every minute, but in my opinion this is rudeness. On the other hand, sending DNS requests for your AAAA is, in a sense, pale, so this part of the script can be considered optional. curl -m 30 https://freedns.afraid.org/dynamic/update.php?bnJxM3kxMHRHF1p4B0NmSXJDfEFLc0NJOjEzMTEyNjv\&address=$ipv6 2>/dev/null |grep Updated
Updated 1 host(s) myhost.mooo.com to 2001:0:52ab:53b:2ab4:555e:23d0:1dc9 in 0.008 seconds
date >> /var/log/freedns.log
write to the log the date of the successful update AAAA &> /dev/null
cron, please do not worry and do not send us an email every minute about the launch of this scriptSource: https://habr.com/ru/post/246341/
All Articles