IPv6, miredo, dynamic DNS AAAA

I wanted a strange thing - so that my IPv6-enabled (miredo) hosts would also have a dynamically updated DNS record. Having studied the question, I found out that many common dyndns services either do not provide the ability to register AAAA (IPv6 is the equivalent of a type A entry for IPv4), or they do not provide it for free, or they have muddy settings for dynamically updating an unknown level of security (or even http / plaintext). I tried a dozen services and decided to stay at freedns.afraid.org
Pros:
- Human-readable admin panel (without any "buy AAAA for $ 0 USD")
- Free give AAAA
- Secure (https) update
- URL-based update (no need to doubt the config for agents like ddclient)
Of the features - a one-line script for updating AAAA had to be written by myself. It turned out this:
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
Although the script is single-line, it turned out to be a bit long, so I’ll comment on why:
* * * * *
5 stars - information for cron "run it every minute"root
decide for yourself what account to runipv6=$(ip a |grep -s -i -o '2001\:[a-f0-9\.:]*')
We get the ip teredo-address from the exhaust , it works something like this:If the address is found, we put it in the $ ipv6 variable, if it is not found, the assignment fails and no further efforts are made to update the AAAA record (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 )ip a |grep -s -i -o '2001\:[a-f0-9\.:]*' 2001:0:52ab:53b:2ab4:555e:23d0:1dc9
[ "$(nslookup -query=AAAA myhost.mooo.com ns1.afraid.org |grep -s -i -o '2001\:[a-f0-9\.:]*')" != "$ipv6" ]
We poll the server ns1.afraid.org for the subject “what is your current IP address for my AAAA?” And compare it with what miredo has configured for us at the moment. If it matches, you don’t need to do anything, the script is interrupted. Why is their DNS server indicated instead of the system one? To minimize the delay in notifying our script about a record change. On other DNS servers, the change will be with a long delay. It would be possible not to check anything but stupidly peck every minute at the specified URL, but in my opinion this is rudeness. On the other hand, sending DNS queries about your AAAA is in some ways fawn, 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
- Updating our AAAA record (note https)
- bnJxM3kxMHRHF1p4B0NmSXJDfEFLc0NJOjEzMTEyNjv - the personal key for updating our host can be found in the admin freedns.afraid.org in the section Dynamic DNS -> Direct URL
- \ & address = $ ipv6 - actually pass our teredo IPv6 found at the very beginning of the script as a parameter
- 2> / dev / null | grep Updated - check if the update is successful. If successful, the server will issue something like
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 successful update AAAA&> /dev/null
cron, please don’t worry and do not send us an email every minute about running this script