first commit
This commit is contained in:
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
|
||||
BASE_DIR="/mnt/docker-persistent-data/docker"
|
||||
INI_FILE=$BASE_DIR"/last-ip.ini"
|
||||
LOG_FILE=$BASE_DIR"/update-firewall.log"
|
||||
|
||||
CURRENT_IP=$(dig +short lan.ddnsgeek.com)
|
||||
LAST_IP=`cat $INI_FILE`
|
||||
|
||||
CMD_PART_1='allow proto tcp from'
|
||||
CMD_PART_2='to any port 22'
|
||||
|
||||
echo $(date -d "+10 hours" "+%a %b %d %T") > $LOG_FILE
|
||||
echo "Last IP address: "$LAST_IP >> $LOG_FILE
|
||||
echo "Current IP address: "$CURRENT_IP >> $LOG_FILE
|
||||
|
||||
if ! [ $CURRENT_IP == $LAST_IP ];
|
||||
then
|
||||
echo "Updating Firewall Rules" >> $LOG_FILE
|
||||
|
||||
sudo ufw delete $CMD_PART_1 $LAST_IP $CMD_PART_2
|
||||
sudo ufw $CMD_PART_1 $CURRENT_IP $CMD_PART_2
|
||||
echo $CURRENT_IP > $INI_FILE
|
||||
|
||||
else
|
||||
echo "IP address is correct. No firewall changes needed" >> $LOG_FILE
|
||||
fi
|
||||
Reference in New Issue
Block a user