Created
July 26, 2017 16:10
-
-
Save iitenkida7/2714dc67aaad2eeda52f266b0c485aa5 to your computer and use it in GitHub Desktop.
[bash]iptablesDrop
This file contains 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 | |
#iptables を利用して、一時的に、特定のIPをブロックする。 | |
#iptables が再起動されれば、設定はフラッシュしてしまう。 | |
#NATなどで多段構成の時などは、IP間違えに注意する。 | |
function drop_ip(){ | |
IP=$1 | |
IP_CHECK=$(echo ${IP} | egrep "^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$") | |
if [ ! "${IP_CHECK}" ] ; then | |
echo [ERROR] ${IP} is not IP Address. | |
exit 1 | |
fi | |
iptables -I INPUT -s ${IP} -j DROP | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment