2013年4月1日月曜日

iptablesでIPアドレス制限(アクセス制限)

こんな感じで、Webアクセスを限定させてる

iptablesはこう書いて
#!/bin/bash
iptables -F
iptables -Z
iptables -X
iptables -P INPUT DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -s 192.168.0.0/24 -j ACCEPT # LAN
# user chain
iptables -N JAPAN_ONLY
#web
iptables -A INPUT -p tcp -m multiport --dport 80,443 -j JAPAN_ONLY
iptables -A INPUT -p tcp -m multiport --dport 80,443 -m state --state NEW -m hashlimit \
--hashlimit-name web_limit --hashlimit 2/m --hashlimit-burst 5 \
--hashlimit-mode srcip --hashlimit-htable-expire 360000 -j ACCEPT
# user chain read
source /etc/network/japan_only.sh
view raw iptables hosted with ❤ by GitHub


dropは別ファイルにすると便利
#!/bin/bash
iptables -F JAPAN_ONLY
iptables -A JAPAN_ONLY -s 1.0.16.0/20 -j RETURN
iptables -A JAPAN_ONLY -s 223.223.208.0/21 -j RETURN
iptables -A JAPAN_ONLY -s 223.223.224.0/19 -j RETURN
#↓以下続く
iptables -A JAPAN_ONLY -j DROP
view raw japan_only.sh hosted with ❤ by GitHub



参考リンク
iptablesで日本のIPアドレスからのアクセスのみ許可する
iptables の RETURN の使い方

0 件のコメント: