Skip to content

Instantly share code, notes, and snippets.

@shlomi-noach
Created November 15, 2015 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shlomi-noach/a2a2a65872529c1f34d2 to your computer and use it in GitHub Desktop.
Save shlomi-noach/a2a2a65872529c1f34d2 to your computer and use it in GitHub Desktop.
Block/unblock MySQL 3306 access via iptables
#!/bin/bash
#
# Usage: block_mysql_access.bash [true|false]
# "true" or empty input blocks 3306 access, via iptables
# "false" re-enables access to 3306
#
if [ $# -eq 0 ] || [ "$1" == "true" ]; then
sudo -i /sbin/iptables -I INPUT -p tcp --destination-port 3306 -j REJECT
elif [ "$1" == "false" ]; then
sudo -i /sbin/iptables -D INPUT -p tcp --destination-port 3306 -j REJECT
else
echo "Bad input"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment