22 lines
572 B
Bash
Executable File
22 lines
572 B
Bash
Executable File
#!/bin/bash
|
|
HOSTNAME='agnhome.agnav.com'
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "This script must be run as root"
|
|
exit 1
|
|
fi
|
|
|
|
new_ip=$(host $HOSTNAME | tail -n1 | cut -f4 -d ' ')
|
|
old_ip=$(/usr/sbin/ufw status | grep $HOSTNAME | head -n1 | tr -s ' ' | cut -f3 -d ' ')
|
|
|
|
if [ "$new_ip" = "$old_ip" ] ; then
|
|
echo IP address has not changed
|
|
else
|
|
echo newIP: $new_ip
|
|
if [ -n "$old_ip" ] ; then
|
|
/usr/sbin/ufw delete allow from $old_ip to any
|
|
fi
|
|
/usr/sbin/ufw insert 1 allow from $new_ip to any comment $HOSTNAME
|
|
echo UFW rules have been updated
|
|
fi
|