Added dns::nsupdate class to be used for ddns updates.

This commit is contained in:
Timo Mkinen 2009-10-30 00:52:54 +02:00
parent 9a4a9a6888
commit c99fe8874a
2 changed files with 92 additions and 0 deletions

View file

@ -68,3 +68,46 @@ class dns::server {
}
}
# Install dynamic DNS update script
#
# === Global variables
#
# $dns_nsupdate_name:
# FQDN to update into DNS.
#
# $dns_nsupdate_key:
# DNS key to use when updating entry. Usually in format:
# <keyname> <secret>
# for example:
# gw1.example.com. sZ6GgTZLBX83LXCoo
#
# $dns_nsupdate_server:
# DNS server address where to update entry.
#
# $dns_nsupdate_zone:
# Zone name to update. Defaults to domain part of
# $dns_nsupdate_name variable.
#
class dns::nsupdate {
file { "/usr/local/sbin/nsupdate.sh":
ensure => present,
content => template("dns/nsupdate.sh.erb"),
mode => 0700,
owner => root,
group => $operatingsystem ? {
openbsd => wheel,
default => root,
},
}
cron { "nsupdate":
ensure => present,
command => "/usr/local/sbin/nsupdate.sh",
minute => "*/5",
require => File["/usr/local/sbin/nsupdate.sh"],
}
}

View file

@ -0,0 +1,49 @@
#!/bin/sh
DNSSERVER="<%= dns_nsupdate_server -%>"
DNSZONE="<% if defined?(dns_nsupdate_zone) -%><%= dns_nsupdate_zone -%><% end %>"
MYNAME="<%= dns_nsupdate_name -%>"
MYKEY="<%= dns_nsupdate_key -%>"
# if zone is not defined take it from fqdn
if [ "${DNSZONE}" = "" ]; then
DNSZONE=`echo ${MYNAME} | cut -d . -f 2-`
fi
# determine our current address
case `uname` in
Linux)
MYIF="`route -n | awk '/^0.0.0.0/ { print $8 }'`"
MYADDR="`ifconfig ${MYIF} | sed -n '/inet/s/.*addr:\([0-9.]*\).*/\1/p'`"
;;
OpenBSD)
MYADDR="`route -n get default | awk '/if address/ { print $3 }'`"
;;
esac
# try to get current addr/name from dns
CURADDR=`dig +noall +answer @${DNSSERVER} ${MYNAME} A | awk '{ print $5 }'`
if [ $? -ne 0 ]; then
# we should get this only in dns errors so exit quietly
exit 1
fi
# exit now if we are up to date
if [ ${CURADDR} = ${MYADDR} ]; then
exit 0
fi
# update record
nsupdate -v <<EOF
server ${DNSSERVER}
zone ${DNSZONE}
key ${MYKEY}
update delete ${MYNAME}
update add ${MYNAME} 60 A ${MYADDR}
show
send
EOF