Created
August 16, 2013 12:24
-
-
Save saitodev/6249444 to your computer and use it in GitHub Desktop.
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/sh | |
# -*- coding: utf-8 -*- | |
IPTABLES=/sbin/iptables | |
SERVICE=/sbin/service | |
SSH_PORT=22 | |
$IPTABLES -F # すべてのチェインの内容を削除 | |
$IPTABLES -P INPUT ACCEPT # INPUTチェインのポリシーをACCEPTにする | |
$IPTABLES -P OUTPUT ACCEPT # OUTPUTチェインのポリシーをACCEPTにする | |
$IPTABLES -P FORWARD ACCEPT # FORWARDチェインのポリシーをACCEPTにする | |
$IPTABLES -A INPUT -i lo -j ACCEPT # ローカルホストを許可 | |
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT # 確立済みと関連するコネクションを許可 | |
$IPTABLES -A INPUT -p icmp -j ACCEPT # ICMPパケットを許可 | |
$IPTABLES -A INPUT -p tcp --dport $SSH_PORT -j ACCEPT # SSHを許可 | |
$IPTABLES -A INPUT -p tcp --dport 80 -j ACCEPT # HTTP | |
# ここまでのチェックに引っかからなかったパケットは、ICMPパケット"host-prohibited"を返して接続拒否 | |
$IPTABLES -A INPUT -j REJECT --reject-with icmp-host-prohibited | |
$IPTABLES -A FORWARD -j REJECT --reject-with icmp-host-prohibited | |
$SERVICE iptables save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment