update_ip.sh 731 B

12345678910111213141516171819202122232425
  1. #! /bin/bash
  2. # This script is used on the dns server to do the actual update of the zone file
  3. zone=""
  4. subdomain=""
  5. old_ipv4=$(dig +short a ${subdomain} @127.0.0.1)
  6. new_ipv4=$(cat /var/www/dnsping/tmp/ipv4_address)
  7. old_ipv6=$(dig +short aaaa ${subdomain} @127.0.0.1)
  8. new_ipv6=$(cat /var/www/dnsping/tmp/ipv6_address)
  9. if [ "$new_ipv4" != "$old_ipv4" ] || [ "$new_ipv6" != "$old_ipv6" ];
  10. then
  11. nsupdate -l << EOF
  12. zone $zone
  13. update delete ${subdomain} A
  14. update delete ${subdomain} AAAA
  15. update add ${subdomain} 10 A $new_ipv4
  16. update add ${subdomain} 10 AAAA $new_ipv6
  17. show
  18. send
  19. EOF
  20. logger "Updated dynamic IPv4 address from $old_ipv4 to $new_ipv4"
  21. logger "Updated dynamic IPv6 address from $old_ipv6 to $new_ipv6"
  22. fi