Skip to content

Instantly share code, notes, and snippets.

@iitenkida7
Created July 26, 2017 16:10
Show Gist options
  • Save iitenkida7/2714dc67aaad2eeda52f266b0c485aa5 to your computer and use it in GitHub Desktop.
Save iitenkida7/2714dc67aaad2eeda52f266b0c485aa5 to your computer and use it in GitHub Desktop.
[bash]iptablesDrop
#!/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