Last active
May 1, 2019 00:28
-
-
Save JonTheNiceGuy/708cddb64a3958dd1498 to your computer and use it in GitHub Desktop.
This is a DDNS updater for the freedns.afraid.org service. It updates the DNS entries for two separate connected IP networks (for example, if you have work and personal ADSL) by amending the routing on the box. Note, you'll still need proper routing once it's inside your network!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Authored by Jon Spriggs (jon@sprig.gs) on 2015-03-10 | |
# Based on the DDNS script at afraid.org | |
#!/bin/bash | |
# ALTERNATE ROUTE | |
# This is the path for the second DDNS update to take | |
NEW_ROUTE=192.168.1.1 | |
# TUNNELBROKER.NET CONFIGURATION | |
# USERNAME: This is the username you log into tunnelbroker.net with | |
TBN_USERNAME="" | |
# PASSWORD: This is the per-tunnel authenticator, found on the "Advanced" tab as "Update Key" | |
TBN_PASSWORD="" | |
# TUNNELID: This is the tunnel ID, found on the "IPv6 Tunnel" tab as "Tunnel ID" | |
TBN_TUNNELID="" | |
# FREEDNS.AFRAID.ORG CONFIGURATION | |
# Get this from the "Direct URL" link on http://freedns.afraid.org/dynamic/ | |
FEO_URL_1="http://freedns.afraid.org/dynamic/update.php?<HOSTID>" | |
# This is the host name it refers to (or an alias of your choice) - just used for logs | |
FEO_Name_1="DDNS-Name-1" | |
# Get this from the "Direct URL" link on http://freedns.afraid.org/dynamic/ | |
FEO_URL_2="http://freedns.afraid.org/dynamic/update.php?<HOSTID>" | |
# This is the host name it refers to (or an alias of your choice) - just used for logs | |
FEO_Name_2="DDNS-Name-2" | |
####################################### VARIABLE MAPPING | |
# This URL found here: https://forums.he.net/index.php?topic=1994.0 | |
TBN_URL="https://ipv4.tunnelbroker.net/nic/update?username=${TBN_USERNAME}&password=${TBN_PASSWORD}&hostname=${TBN_TUNNELID}" | |
# Used in log files and updates | |
TBN_Name="Tunnel-${TBN_TUNNELID}" | |
############################## SCRIPT PROPER STARTS HERE | |
############################## DO NOT TOUCH BELOW THIS LINE! | |
VERBOSE=0 | |
# Enable or disable limited debugging | |
if [ -n "$1" ]; then | |
case $1 in | |
verbose|--verbose|-v)VERBOSE=1;; | |
esac | |
fi | |
# Resolve the DNS name for freedns.afraid.org | |
FREEDNS="`host freedns.afraid.org | cut -d " " -f4`" | |
if [ "$VERBOSE" != "0" ]; then echo "Resolved freedns.afraid.org to $FREEDNS"; fi | |
if [ -z "$FREEDNS" ]; then | |
echo "Failed to identify the gateway address for FreeDNS.Afraid.org - try again later" | |
exit | |
fi | |
# Update first name | |
# - Add route | |
ip -f inet route add $FREEDNS via $NEW_ROUTE | |
cp /etc/hosts /etc/hosts.ddnsmigrate | |
echo "$FREEDNS freedns.afraid.org" >> /etc/hosts | |
if [ "$VERBOSE" != "0" ]; then echo "Added the host route and hosts file entry for freedns.afraid.org"; fi | |
# - Then update record | |
if [ "$VERBOSE" != "0" ] | |
then | |
RUNTIME="`date`" | |
echo "Performing wget against freedns for $FEO_Name_1" | |
OUTPUT="`wget -q -O - $FEO_URL_1`" | |
echo "$OUTPUT" | |
echo -n "$RUNTIME - $OUTPUT" | grep -v "has not changed" >> "/tmp/ddns_${FEO_Name_1}.log" 2>&1 | |
else | |
(echo -n `date` - && wget -q -O - "$FEO_URL_1") | grep -v "has not changed" >> "/tmp/ddns_${FEO_Name_1}.log" 2>&1 | |
fi | |
# Remove route | |
ip -f inet route del $FREEDNS | |
mv /etc/hosts.ddnsmigrate /etc/hosts | |
# Update second name | |
if [ "$VERBOSE" != "0" ] | |
then | |
RUNTIME="`date`" | |
echo "Performing wget against freedns for $FEO_Name_2" | |
OUTPUT="`wget -q -O - $FEO_URL_2`" | |
echo "$OUTPUT" | |
echo -n "$RUNTIME - $OUTPUT" | grep -v "has not changed" >> "/tmp/ddns_${FEO_Name_2}.log" 2>&1 | |
else | |
(echo -n `date` - && wget -q -O - "$FEO_URL_2") | grep -v "has not changed" >> "/tmp/ddns_${FEO_Name_2}.log" 2>&1 | |
fi | |
# Update HE TunnelBroker.net | |
if [ "$VERBOSE" != "0" ] | |
then | |
RUNTIME="`date`" | |
echo "Performing wget against tunnelbroker for $TBN_Name" | |
OUTPUT="`wget -q -O - $TBN_URL`" | |
echo "$OUTPUT" | |
echo -n "$RUNTIME - $OUTPUT" | grep -v "nochg" >> "/tmp/ddns_${TBN_Name}.log" 2>&1 | |
else | |
(echo -n `date` - && wget -q -O - "$TBN_URL") | grep -v "nochg" >> "/tmp/ddns_${TBN_Name}.log" 2>&1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note, this doesn't work on IPv6 networks. Working to revise it.