Skip to content

Instantly share code, notes, and snippets.

@Khoulaiz
Created August 30, 2013 13:46
Show Gist options
  • Save Khoulaiz/6390005 to your computer and use it in GitHub Desktop.
Save Khoulaiz/6390005 to your computer and use it in GitHub Desktop.
check dyndns hostname and reload iptables to reavaluate dynamic hostnames from iptables config. put this in a cronjob and you can use dyndns entries in iptables configs.
#!/bin/bash
# check dyndns name of a host and reset iptables if change was detected
HOSTNAME=<hostname-to-check.dyndns.org>
LOGFILE=/var/run/check_home_ip
Current_IP=$(/usr/bin/dig +short $HOSTNAME)
if [ $LOGFILE = "" ] ; then
iptables-restore </etc/iptables_rules
echo $Current_IP > $LOGFILE
else
Old_IP=$(cat $LOGFILE)
if [ "$Current_IP" = "$Old_IP" ] ; then
touch $LOGFILE
echo IP address has not changed
else
iptables-restore </etc/iptables.rules
echo $Current_IP > $LOGFILE
echo iptables has been updated
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment