If your server is behind a connection that may change its public IP and your registrar is LeBUreau, here is a way to update automatically the DNS zone.
First, create your nsupdate key file /PATH/TO/YOUR/KEY.key based on information given by Lebureau. Its content should look something like :
key "lebureau_coop_domain_tld" {
algorithm hmac-sha512;
secret "A_STRONG_AND_LONG_SECRET";
};
then you create a bash script /opt/nsupdate/nsupdate-dynip :
#!/usr/bin/env bash
ECHO=$(which echo)
NSUPDATE=$(which nsupdate)
# Set the DNS entry you want to update, please notice the final dot.
HOST="sub.domain.tld."
# Set the key provided by your DNS administrator
KEY="/PATH/TO/YOUR/KEY.key"
# Set the DNS server name or IP
SERVER="ns1.lebureau.coop"
# Set the zone to modify, it can be any zone previous key has permissions to modify
ZONE="domain.tld."
# Get your current public IP address
wget --quiet -O NewIP.txt https://ip.yunohost.org
IP=$(cat NewIP.txt)
rm NewIP.txt
# Get the public IP registered in DNS zone
OLDIP=`dig $HOST +short @45.13.107.8`
if [ "$IP" != "$OLDIP" ];
then
$ECHO "server $SERVER" > /tmp/nsupdate
$ECHO "debug yes" >> /tmp/nsupdate
$ECHO "zone $ZONE" >> /tmp/nsupdate
$ECHO "update delete $HOST" >> /tmp/nsupdate
$ECHO "update add $HOST 3600 A $IP" >> /tmp/nsupdate
$ECHO "send" >> /tmp/nsupdate
fi
$NSUPDATE -k ${KEY} -v /tmp/nsupdate >> /var/log/nsupdate-dynip.log 2>&1
Don’t forget to make this file executable : chmod u+x /opt/nsupdate/nsupdate-dynip
then, you add to crontab -e :
*/5 * * * * [ -x /opt/nsupdate/nsupdate-dynip ] && /opt/nsupdate/nsupdate-dynip
based on adocampo work : nsupdate-dynip/nsupdate-dynip at master · adocampo/nsupdate-dynip · GitHub