Reply To: Multiple WAN interfaces and Dynamic DNS

Home Page Forums Network Management ZeroShell Multiple WAN interfaces and Dynamic DNS Reply To: Multiple WAN interfaces and Dynamic DNS

#50508

aviegas
Member

To wrapup, I have written a small script to properly handle a per interface DynDNS control. No need to resort to tagging to get the packet out thru the proper interface.

Make the script available and start it from the “post” boot script as:

dyndns interface hostname authentication waitinterval

ex:

dyndns ETH01 myhost.dnsalias.com joedoe:lame 120

Do not forget to place the script in the background (& at the end). To make it safer, I’m also adding a cron based script to run every 1 hour to

killall -w dyndns

and then repeat the whole startup process. This is manual configuration, but work fine.

The original DDNS script of SZ is not very “smart”. As I understant it, it just ignores the interface concept (it will take the
route that is available) and the IP address that will be registered will be the one of the “lucky” interface.

#!/bin/sh
. /etc/kerbynet.conf
INTERFACE="$1"
HOSTNAME="$2"
AUTH="$3"
INTERVAL="$4"

ERROR="/tmp/dyndns.$INTERFACE.err"
RESULT="/tmp/dyndns.$INTERFACE.out"
LAST_IP="X"

while true ; do
sleep $INTERVAL
NEW_IP=`ip addr show $INTERFACE 2> /dev/null | grep inet | awk '{ sub(///, " ") ; print $2 }'`
if [ -n "$NEW_IP" -a "$NEW_IP" != "$LAST_IP" ]; then
DNS_IP=`host $HOSTNAME 2> /dev/null | cut -d" " -f4`
if [ "$NEW_IP" != "$DNS_IP" ]; then
logger -t DDNS "DynDNS change required for internet $INTERFACE ($HOSTNAME)"
logger -t DDNS "==> new ip: $NEW_IP - old ip: $DNS_IP"
if wget -q -t 3 -w 20 if wget -t 3 -w 20 -o "$ERROR" -O "$RESULT" "http://${AUTH}@members.dyndns.org/nic/update?hostname=${HOSTNAME}&myip=${NEW_IP}&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"; then
logger -t DDNS "==> `cat $RESULT`"
else
logger -t DDNS "ERROR:"
grep -v " => " "$ERROR" | logger -t DDNS
fi
sleep 60
fi
else
LAST_IP="$NEW_IP"
fi
done