Created
December 15, 2019 17:20
-
-
Save cmbuckley/cb56055c7741a226286ecb0becb503c9 to your computer and use it in GitHub Desktop.
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 | |
HOSTNAME=your.dns.here | |
UFW=/usr/sbin/ufw | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
new_ip=$(dig +short $HOSTNAME) | |
old_ip=$($UFW status | grep $HOSTNAME | head -n1 | tr -s ' ' | cut -f3 -d ' ') | |
if [ "$new_ip" = "$old_ip" ] ; then | |
echo IP address has not changed | |
else | |
if [ -n "$old_ip" ] ; then | |
$UFW delete allow from $old_ip to any | |
fi | |
$UFW allow from $new_ip to any comment $HOSTNAME | |
echo firewall has been updated | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment