Scripts/dynsupdate: Difference between revisions

From fakedWiki
Jump to: navigation, search
(Created page with "This script will update the A records for zones you host on your local Bind9 nameserver to your (external) dynamic IP. Make sure that nsupdate works with a key by testing it manu…")
 
m (1 revision imported)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
This script will update the A records for zones you host on your local Bind9 nameserver to your (external) dynamic IP. Make sure that nsupdate works with a key by testing it manually.
This script will update the A records for zones you host on your local Bind9 nameserver to your (external) dynamic IP. Make sure that nsupdate works with a key by testing it manually.
I'm running this script after every reconnect of my VDSL link through ppp's ip-up scripts by putting it here:
<pre>
/etc/ppp/ip-up.d/dynsupdate
</pre>


'''Notice:''' The here-document lines (between EndOfCommands) have to be indented with tabs, or not indented at all - spaces will not work.
'''Notice:''' The here-document lines (between EndOfCommands) have to be indented with tabs, or not indented at all - spaces will not work.
Line 8: Line 13:
SERVER="192.168.0.XXX"
SERVER="192.168.0.XXX"
KEY="/etc/bind/Knsupdate.key"
KEY="/etc/bind/Knsupdate.key"
TTL="300"


IP=`lynx -dump http://checkip.dyndns.org | awk '{print $4}'`
IP=`lynx -dump http://checkip.dyndns.org | awk '{print $4}'`
Line 22: Line 28:
     COMMANDS="$COMMANDS
     COMMANDS="$COMMANDS
         update delete ${RECORD}. A
         update delete ${RECORD}. A
         update add ${RECORD}. 300 A ${IP}
         update add ${RECORD}. ${TTL} A ${IP}
         "
         "
     echo "updating record: $RECORD"
     echo "updating record: $RECORD"

Latest revision as of 20:10, 26 August 2016

This script will update the A records for zones you host on your local Bind9 nameserver to your (external) dynamic IP. Make sure that nsupdate works with a key by testing it manually.

I'm running this script after every reconnect of my VDSL link through ppp's ip-up scripts by putting it here:

/etc/ppp/ip-up.d/dynsupdate

Notice: The here-document lines (between EndOfCommands) have to be indented with tabs, or not indented at all - spaces will not work.

#!/bin/bash

RECORDS=("example.com" "ns1.example.com" "ns2.example.com" "example.org" "example.net")
SERVER="192.168.0.XXX"
KEY="/etc/bind/Knsupdate.key"
TTL="300"

IP=`lynx -dump http://checkip.dyndns.org | awk '{print $4}'`

if [ -e "/tmp/nsup.IP" ]; then
  read OLD_IP < "/tmp/nsup.IP"
else
  OLD_IP="0.0.0.0"
fi

if [ "$IP" != "$OLD_IP" ]; then
  echo "IP address changed from $OLD_IP to $IP"
  for RECORD in ${RECORDS[@]}; do
    COMMANDS="$COMMANDS
        update delete ${RECORD}. A
        update add ${RECORD}. ${TTL} A ${IP}
        "
    echo "updating record: $RECORD"
  done
  nsupdate -v -k ${KEY} <<-EndOfCommands
        server ${SERVER}
        ${COMMANDS}
        send
        EndOfCommands
  echo "$IP" > /tmp/nsup.IP
  echo "IP updates done"
fi