Created
August 30, 2013 13:46
-
-
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.
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/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