2024-02-11 ddnsupdate v.1.0.22 Script for dynamic DNS updates according to RFC 2136 of your bind name server using nsupdate command and TSIG key pairs. The script gets the IP address of a host and maintains a DNS record for it. It supports several modes: - IP from DHCP You may use the script as a dhcp exit hook. It understands the messages from ISC dhclient. - public IP Use a checkip or raw web service to get the public IP for your host and register it. - IP of the main interface The script can extract the IP from the interface, where the default gateway is set. Features: * expected IP -> fallback You may define a set of IP addresses you expect to have for your host. If the current IP is not within the set, a fallback IP can be registered. * recheck name always, by time interval or never Recheck the name in DNS before trying to register. If the name is correctly returned, no registering is needed. The scripts takes a note of the registered address anyway and acts accordingly to not re-register an unchanged address. * use of multiple public IP services supported * various checks of the host's online status and reasons why registering may not be possible * IPv6 capable Requirements: Runs in bash, tested under Devuan GNU+Linux. Install nsupdate, html2text, fping, dig, curl and the usual suspects like sed, grep, etc. Set up your name server to accept zone updates. See the comments in the beginning of the script letsencrypt_acme_dns-01_challenge_hook, how to allow dynamic updates using TSIG-keys: https://ente.limmat.ch/ftp/pub/software/bash/letsencrypt/letsencrypt_acme_dns-01_challenge_hook Installation: Download the script to your /usr/local/sbin directory. Set ownership to root:root and the right to execute for the owner. Edit the script and set the variables in the header suiting your environment. Consider setting up a system user to run the script, root privileges are not needed. You should prevent normal users of executing the script though. Usage: ddnsupdate [--quiet|-q|--version|-v|--help|-h|-?] [ [] ] is the reason as given by ISC dhclient and additionally NONDHCP and NONDHCP6. Setting a is not meant to happen in normal operation. Let this script execute from cron, from ISC dhclient as an exit hook and/or from ifupdown. You need to figure out yourself what mechanisms you need to combine. Using cron with a short interval is recommended for dynamic, public IPs in a combination with other mechanisms. - cron: edit /etc/cron.d/ddnsupdate and set its content to: ----snip---- # /etc/cron.d/ddnsupdate: Register our host's address in DNS. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin */1 * * * * root /usr/local/sbin/ddnsupdate -q ----snip---- - dhclient: edit /etc/dhcp/dhclient-exit-hooks.d/ddnsupdater and set its content to: ----snip---- # dhclient-exit-hook: ddnsupdater RUN="yes" if [ "$RUN" = "yes" ]; then # Update DNS /usr/local/sbin/ddnsupdate $reason $new_ip_address fi ----snip---- - ifupdown: edit /etc/network/interfaces and set a directive to an interface stanza like the following: post-up /usr/local/sbin/ddnsupdate -q pre-down /usr/local/sbin/ddnsupdate -q DELETE pre-down /usr/local/sbin/ddnsupdate -q DELETE6 Notes: - Try ddnsupdate on the command line first before setting up a mechanism described above. - Running as root is discouraged and unnecessary. Set up a system user but leave your TSIG keys secured! Do not allow normal users to execute the script. - dhclient's exit and enter hooks are not working to my satisfaction: It seems the connection on a interface is already down for dhclient's enter hook on a RELEASE or DELETE event: Like this a registration cannot be removed from the DNS. This needs more testing and is not solved yet. - Documentation is not ready and may improve with time. You're reading it right now ... Feedback: Please use the web form under http://ente.limmat.ch/feedback/. Bugs: I guess there are some. It is possible to set up the script in ways it does not behave ideally. I did not foresee all setup scenarios and thus, think about how you use the script. Nevertheless I am glad to receive a hint if there is a bug. Use the feedback link above to report. Source: Well, it's a bash script. Download: https://ente.limmat.ch/ftp/pub/software/bash/ddnsupdate/ License: GNU General Public License Version 2. Have fun. Regards, Adrian. (c) 2013-2024 by Adrian Zaugg under GNU General Public License Version 2.