Created
November 18, 2021 21:05
-
-
Save jasonbronson/d93830bd59d6935be5eab17d55ced990 to your computer and use it in GitHub Desktop.
Update ip address bash script for UFW firewall
This file contains hidden or 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 | |
#allow a dyndns name | |
PATH="/usr/sbin:/usr/bin" | |
HOSTNAME=home.bronson.dev | |
LOGFILE=/tmp/updateip.log | |
Current_IP=$(host $HOSTNAME | cut -f4 -d' ') | |
touch $LOGFILE | |
if [ $LOGFILE = "" ] ; then | |
ufw allow from $Current_IP | |
echo $Current_IP > $LOGFILE | |
else | |
Old_IP=$(cat $LOGFILE) | |
# if [ "$Current_IP" = "$Old_IP" ] ; then | |
# echo IP address has not changed | |
# else | |
yes y |ufw delete $(ufw status numbered |(grep $Old_IP|awk -F"[][]" '{print $2}')) | |
ufw 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