-
-
Save fabiofdsantos/68a9ee4f8fa4598e39fe4f19103a33a7 to your computer and use it in GitHub Desktop.
Reload iptables if... (e.g. ip was changed)
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 | |
# Reload iptables if... (e.g. ip was changed) | |
# Dependencies: dig (apt-get install dnsutils in debian/ubuntu) | |
# Note: Run "touch ~/current_ip" and add a new cron job with cmd "crontab -e" to run this script periodically. | |
HOSTNAME=<hostname-to-check.dyndns.org> | |
LOGFILE=~/current_ip | |
Current_IP=$(dig +short $HOSTNAME) | |
if [ $LOGFILE = "" ] ; then | |
iptables-restore < /etc/iptables/rules.v4 | |
echo $Current_IP > $LOGFILE | |
else | |
Old_IP=$(cat $LOGFILE) | |
if [ "$Current_IP" != "$Old_IP" ] ; then | |
iptables-restore < /etc/iptables/rules.v4 | |
echo $Current_IP > $LOGFILE | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment