📜 ⬆️ ⬇️

IPv6, miredo, dynamic DNS AAAA



I wanted a strange one - so that my IPv6-enabled (miredo) hosts also had a dynamically updated DNS record. After studying the question, I found out that many common dyndns services either do not provide AAAA registration (IPv6 equivalent of type A record for IPv4), either do not provide it for free, or have muddy dynamic update settings of unknown security level (or http / plaintext). I tried about a dozen services and decided to stop at freedns.afraid.org
Pros:
Of the features - one-line script for updating AAAA had to write 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 

The script, though single-line, still turned out to be a bit long, so I will comment on what is there for:
')
 * * * * * 
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 

 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 script

Source: https://habr.com/ru/post/246341/


All Articles