Skip to content

Instantly share code, notes, and snippets.

@matthewblott
Created December 3, 2021 16:37
Show Gist options
  • Save matthewblott/8c9c6c790f7504c0bb2f0ae5ef8ec863 to your computer and use it in GitHub Desktop.
Save matthewblott/8c9c6c790f7504c0bb2f0ae5ef8ec863 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Update the ufw rules to allow access for the supplied IP address to the port specified below.
# If a rule already exists it will be deleted.
# This script was created to get round server restrictions when working at home without allowing open
# public access.
PORT=1433
ip=$1
if [ -z "$ip" ]; then
echo "ip address wasn't supplied"
exit 1
fi
# delete old rule
ufw --force delete $(sudo ufw status numbered | (grep 'Home' | awk -F"[][]" '{print $2}'))
ufw insert 5 allow from $ip to any port $PORT comment "Home"
echo "new rules ..."
ufw status numbered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment