Created
April 25, 2012 08:04
-
-
Save uechi-y/2488077 to your computer and use it in GitHub Desktop.
iptables settings
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/sh | |
# さくらVPSで使っている iptables の設定 | |
sshport=$(grep ^Port /etc/ssh/sshd_config | cut -d' ' -f2) | |
iptables=/sbin/iptables | |
$iptables -F | |
$iptables -X | |
$iptables -P INPUT DROP | |
$iptables -P OUTPUT DROP | |
$iptables -P FORWARD DROP | |
# ループバックはすべて許可 | |
$iptables -A INPUT -i lo -j ACCEPT | |
$iptables -A OUTPUT -o lo -j ACCEPT | |
# dropbox LAN sync は ログに残さずに Drop する | |
$iptables -A INPUT -p udp --dport 17500 -j DROP | |
# NEWステートで syn ビットの立っていないパケットは拒否 | |
$iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP | |
# セッションが確立したパケットは許可 | |
$iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
$iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT | |
# ping は許可 | |
$iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT | |
$iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT | |
$iptables -A OUTPUT -p icmp --icmp-type echo-request -j ACCEPT | |
$iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT | |
# dns | |
$iptables -A INPUT -p udp --sport 53 -j ACCEPT | |
$iptables -A OUTPUT -p udp --dport 53 -j ACCEPT | |
# http, https | |
$iptables -A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT | |
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT | |
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT | |
# git | |
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 9418 -j ACCEPT | |
# ssh | |
$iptables -A INPUT -p tcp -m state --state NEW --dport $sshport -j ACCEPT | |
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT | |
# smtp | |
$iptables -A INPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT | |
$iptables -A OUTPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT | |
# logging | |
$iptables -N LOGGING | |
$iptables -A LOGGING -j LOG --log-level warning --log-prefix "DROP:" -m limit | |
$iptables -A LOGGING -j DROP | |
$iptables -A INPUT -j LOGGING | |
$iptables -A OUTPUT -j LOGGING | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment