Created
November 23, 2012 14:21
-
-
Save nicksnell/4135838 to your computer and use it in GitHub Desktop.
UFW Updater (MySQL)
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 | |
| target_hosts="dynhost.does-not-exist.com another-host.does-not-exist.com" | |
| if [ -f "/root/mysql-allow-hosts-current" ]; then | |
| mv /root/mysql-allow-hosts-current /root/mysql-allow-hosts-prev | |
| fi | |
| touch /root/mysql-allow-hosts-current | |
| if [ -f "/root/mysql-allow-hosts-prev" ]; then | |
| # Remove previously set firewall allows | |
| for prev_ip in `cat /root/mysql-allow-hosts-prev`; do | |
| ufw delete allow from $prev_ip to any port 3306 > /dev/null | |
| done | |
| fi | |
| for target_host in $target_hosts; do | |
| # Look up IP per host | |
| # echo "Looking up IP for host:" $target_host | |
| target_ip=`host $target_host | cut -d ' ' -f 4` | |
| if [ $? -eq 0 ]; then | |
| echo $target_ip >> /root/mysql-allow-hosts-current | |
| ufw allow from $target_ip to any port 3306 > /dev/null | |
| fi | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from awesome script here: http://superuser.com/questions/79855/how-to-use-fqdn-in-firewall-rules-for-gnu-linux/84988#84988