Created
December 18, 2019 09:07
-
-
Save pacmac/5e0337f43f62f65f09c3c4ab483a1d18 to your computer and use it in GitHub Desktop.
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 | |
HOSTNAME="my.domain.com" | |
LOGFILE=$HOME/ufw.log | |
Current_IP=$(host $HOSTNAME | head -n1 | cut -f4 -d ' ') | |
if [ ! -f $LOGFILE ]; then | |
/usr/sbin/ufw insert 1 allow from $Current_IP to any port 22 proto tcp | |
echo $Current_IP > $LOGFILE | |
else | |
Old_IP=$(cat $LOGFILE) | |
if [ "$Current_IP" = "$Old_IP" ] ; then | |
echo IP address has not changed | |
else | |
/usr/sbin/ufw delete allow from $Old_IP | |
/usr/sbin/ufw insert 1 allow from $Current_IP | |
echo $Current_IP > $LOGFILE | |
echo iptables have been updated | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment