from : http://www.91linux.com/html/article/shell/20090730/17665.html
脚本如下:::
#!/bin/sh
#ver 1.1
#date 2009.7.14
IPTABLES=/sbin/iptables
INT_NET=192.168.1.0/24
MDPROBE=/sbin/modprobe
ifconfig eth0 192.168.1.4 netmask 255.255.255.0
ifconfig eth1 202.103.24.68 netmask 255.255.255.0
route add default gw 192.168.1.4
###SETTING UP rules and chain policy to DROP
$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -X
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
#load modprobe##
$MODPROBE ip_conntrack
$MODPROBE iptable_nat
$MODPROBE ip_conntrack_ftp
$MODPROBE ip_nat_ftp
#setting ip INPUT rules.....
echo setting up INPUT chain....
$IPTABLES -A INPUT -m state --state INVIALID -j LOG --log-prefix "DROP INVIALID"--log-ip-options --log-tcp-options
$IPTABLES -A INPUT -m state --state INVIALTD -j DROP
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A INPUT -i eth0 -s ! $INT_NET -j LOG --log-prefix "SPOOFED PKT"
$IPTABLES -A INPUT -i eth0 -s ! $INT_NET -j DROP
#ACCEPT rules...
$IPTABLES -A INPUT -i eth0 -p tcp -s $INT_NET --dport 22 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p icm
p --icmp-type echo-request -j ACCEPT
$IPTABLES -A INPUT -i ! lo -j LOG --log-prefix "DROP" --log-ip-options --log-tcp-options
#setting up OUTPUT chain rules.....
$IPTABLES -A OUTPUT -m state --state INVIALID -j LOG --log-prefix "DROP INVIALID"--log-ip-options --log-tcp-options
$IPTABLES -A OUTPUT -m state --state INVIALTD -j DROP
$IPTABLES -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
###########
$IPTABLES -A OUTPUT -p tcp --dport 22 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 20 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 21 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 25 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 80 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 110 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 143 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p tcp --dport 443 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -p udp --dport 53 -m state --state NEW -j ACCEPT
#####
$IPTABLES -A OUTPUT -i ! lo -j LOG --log-prefix "DROP" --log-ip-options --log-tcp-options
#####
echo setting up FORWARD chain rules.....
$IPTABLES -A FORWARD -m state --state INVIALID -j LOG --log-prefix "DROP INVIALID"--log-ip-options --log-tcp-options
$IPTABLES -A FORWARD -m state --state INVIALTD -j DROP
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
####SETTING UP RULES
$IPTABLES -A FORWARD -i eth0 -s ! $INT_NET -j LOG --log-prefix "SPOOFED PKT"
$IPTABLES -A FORWARD -i eth0 -s ! $INT_NET -j DROP
####
$IPTABLES -A FORWARD -p tcp --dport 20 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 21 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp -i eth0 -s $INT_NET --dport 22 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp -i eth0 -s $INT_NET --dport 22 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 25 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 80 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 443 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p udp --dport 53 -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -p tcp --dport 43 --syn -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -i ! lo -j LOG --log-prefix "DROP" --log-ip-options --log-tcp-option
#####nat
$IPTABLES -t nat -A PREROUTING -p tcp --dport 80 -i eth1 -j DNAT --to 192.168.1.4:80
$IPTABLES -t nat -A PREROUTING -p tcp --dport 21 -i eth1 -j DNAT --to 192.168.1
.4:21
$IPTABLES -t nat -A PREROUTING -p tcp --dport 20 -i eth1 -j DNAT --to 192.168.1
.4:20
$IPTABLES -t nat -A PREROUTING -p tcp --dport 443 -i eth1 -j DNAT --to 192.168.1.4:443
$IPTABLES -t nat -A PREROUTING -p udp --dport 53 -i eth1 -j DNAT --to 192.168.1
.4:53
$IPTABLES -t nat -A POSTROUTING -s $INT_NET -o eth1 -j MASQUERDE