Skip to content

Instantly share code, notes, and snippets.

@pcfe
Created April 2, 2018 15:15
Show Gist options
  • Save pcfe/88832969de41a68bb1acb905af4b7fd6 to your computer and use it in GitHub Desktop.
Save pcfe/88832969de41a68bb1acb905af4b7fd6 to your computer and use it in GitHub Desktop.
DynDNS updates with TSIG and /etc/ppp/ip-up.local but without NetworkManager
#!/bin/bash
#
# adapted from
# NetworkManager dispatcher script to update dyndns via TSIG using nsupdate
# http://centos5.pcfe.net/wordpress/2011/09/dyndns-updates-with-tsig-and-networkmanager-dispatcher/
# http://www.pcfe.net/octopress/blog/2011/09/13/dyndns-updates-with-tsig-and-networkmanager-dispatcher/
# pcfe, 2012-09-07
#
# adaptation of http://messinet.com/trac/browser/networkmanager-nsupdate-gss-tsig/20-nsupdate-gss-tsig
# read https://www.dyndns.com/account/settings/tsig.html
# and https://www.dyndns.com/support/kb/ddns_updates_and_tsig.html
# pcfe, 2011-09-13
#
# set -x
# http://www.tldp.org/HOWTO/PPP-HOWTO/x1455.html
# When the ppp link comes up, this script is called with the following
# parameters
# $1 the interface name used by pppd (e.g. ppp3)
# $2 the tty device name
# $3 the tty device speed
# $4 the local IP address for the interface
# $5 the remote IP address
# $6 the parameter specified by the 'ipparam' option to pppd
#
#
# Function definitions
#
# Invoke nsupdate
# (vars defined below)
updateRRs() {
(echo "server update.dyndns.com"
echo "zone ${ZONE}"
echo "key ${KEY_NAME} ${KEY_HMAC}"
echo "update add ${HOST}.${ZONE} ${TTL} A ${ADDR}"
echo "send"
) | nsupdate -t 60 || exit 1
}
#
# Start working...
#
# Set the host name & ttl
ADDR=`/sbin/ifconfig $1 | grep "inet addr:" | awk '{print $2}' | awk -F ":" '{print $2}'`
#ADDR=`/sbin/ifconfig $1 | grep "inet " | awk '{print $2}'`
# short TTL so we have the new address shortly after ADSL came up
TTL=60
# the DynDNS hostname and zone you want to update, e.g. myserver.mydomain.net
HOST="myserver"
ZONE="mydomain.net"
# get the next two values from https://www.dyndns.com/account/settings/tsig.html
KEY_NAME="MyKeyName"
KEY_HMAC="MyKeyHMAC"
# Proceed only if called for ppp interface
if [[ "$1" == ppp* ]]
then
# logger "Called as $0 $@."
logger updating DNS to point at $4
updateRRs
else
logger "Not called for ppp interface. Exiting."
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment