Last active
February 15, 2018 16:59
-
-
Save mfakane/6e48d0c4535a9f25a30063911adbf6ee to your computer and use it in GitHub Desktop.
国による IP ブロック
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 | |
cd /tmp | |
curl -O http://nami.jp/ipv4bycc/cidr.txt.gz && gunzip -f cidr.txt.gz | |
ipset create -exist WHITELIST hash:net | |
ipset flush WHITELIST | |
sed -n 's/^JP\t//p' cidr.txt | while read ADDRESS; do ipset add WHITELIST $ADDRESS; done | |
ipset create -exist BLACKLIST hash:net | |
ipset flush BLACKLIST | |
sed -n 's/^\(CH\|AU\)\t//p' cidr.txt | while read ADDRESS; do ipset add BLACKLIST $ADDRESS; done | |
ipset save | |
iptables -F | |
iptables -X | |
iptables -Z | |
# IN 既定でドロップ | |
iptables -P INPUT DROP | |
iptables -P OUTPUT ACCEPT | |
iptables -P FORWARD DROP | |
# INPUT | |
# ループバックは許可 | |
iptables -A INPUT -i lo -j ACCEPT | |
# セッション確立後の通信は許可 | |
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
# SSH 許可 | |
iptables -A INPUT -m state --state NEW -p tcp --dport 22 -m set --match-set WHITELIST src -j ACCEPT | |
iptables-save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment