#!/bin/bash
export PATH=/sbin:/usr/sbin:/bin:/usr/bin
iptables -F
iptables -X
iptables -Z
#遠端 SSH 登陸, 我們要開啟 22 埠
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
#WEB 站群伺服器, 開啟 80 埠
iptables -A INPUT -p tcp –dport 80 -j ACCEPT
#郵件站群伺服器, 開啟 25,110 埠.
iptables -A INPUT -p tcp –dport 110 -j ACCEPT
iptables -A INPUT -p tcp –dport 25 -j ACCEPT
#FTP 站群伺服器, 開啟 20,21 埠
iptables -A INPUT -p tcp -m multiport –dport 21,60000:60050 -j ACCEPT
#如果做了 DNS 站群伺服器, 開啟 53 埠
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p udp –sport 53 -j ACCEPT
iptables -A INPUT -p udp –dport 53 -j ACCEPT
#對 PING 做設定
#iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -j DROP
#所以對別人的請求丟棄應該就可以達到別人無法 PING 的
#iptables -A OUTPUT -p icmp –icmp-type 0 -s localip -j DROP
#其實可以不要 包都丟棄了 還怎麼會發出響應的包呢
iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -j ACCEPT
iptables -A INPUT -p icmp –icmp-type 0 -s 0/0 -j ACCEPT
iptables -A OUTPUT -p icmp –icmp-type 0 -s $FW_IP -j ACCEPT
iptables -A OUTPUT -p icmp –icmp-type 8 -s $FW_IP -j ACCEPT
#開放本機對外部 80 埠
iptables -A INPUT -p tcp ! –syn -s any/0 –sport 80 –dport 1024:65535 -j ACCEPT
iptables -P INPUT DROP
/etc/rc.d/init.d/iptables save
service iptables restart