分类: LINUX
2009-10-25 14:42:30
#!/bin/sh IPT=/sbin/iptables LOCAL_RANGE=192.168.1.0/24 INET_RANGE=1.2.3.0/24 REMOTE_ADMIN_RANGE=4.3.2.0/24 #Clean The Old Tables for TABLE in filter nat mangle ; do $IPT -t $TABLE -F $IPT -t $TABLE -X done $IPT -P INPUT DROP $IPT -P OUTPUT ACCEPT $IPT -A INPUT -s $LOCAL_RANGE -j ACCEPT $IPT -A INPUT -s $INET_RANGE -j ACCEPT $IPT -A INPUT -p tcp -s $REMOTE_ADMIN_RANGE --dport 22 -j ACCEPT $IPT -A INPUT -p tcp --dport 22 -j DROP #Enable TCP SYN Cookie Protection echo 1 > /proc/sys/net/ipv4/tcp_syncookies ######################################################## #Stealth Scans and TCP State Flags #All of the bits are cleared $IPT -A INPUT -p tcp --tcp-flags ALL NONE -j DROP #SYN and FIN are both set $IPT -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP #SYN and RST are both set $IPT -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP #FIN and RST are both set $IPT -A INPUT -p tcp --tcp-flags FIN,RST FIN,RST -j DROP #FIN is the only bit set,without the expected accompanying ACK $IPT -A INPUT -p tcp --tcp-flags ACK,FIN FIN -j DROP #PSH is the only bit set,without the expected accompanying ACK $IPT -A INPUT -p tcp --tcp-flags ACK,PSH PSH -j DROP #URG is the only bit set,without the expected accompanying ACK $IPT -A INPUT -p tcp --tcp-flags ACK,URG URG -j DROP ############################################################# # ICMP Control and Status Message $IPT -A INPUT --fragment -p icmp -j DROP $IPT -A OUTPUT --fragment -p icmp -j DROP ########################################################### #Using Connection State to by-pass Rule Checking $IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT $IPT -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT $IPT -A INPUT -m state --state INVALID -j DROP $IPT -A OUTPUT -m state --state INVALID -j DROP ########################################################### #China NetRange # wget -c # grep cn country-ipv4.lst | awk '{print $5}' > cn.txt while read iprange do $IPT -A INPUT -s $iprange -j ACCEPT done < cn.txt |
#!/bin/sh ipset -N CHINA nethash --hashsize 20000 --probes 2 ########################################################### #China NetRange # wget -c # grep cn country-ipv4.lst | awk '{print $5}' > cn.txt while read iprange do ipset -A CHINA $iprange done < cn.txt iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -A INPUT -m set --match-set CHINA src -j ACCEPT iptables -A OUTPUT -m set --match-set CHINA dst -j ACCEPT |