当前位置: 代码网 > 服务器>网络安全>脚本攻防 > 分享一个不错的iptables脚本

分享一个不错的iptables脚本

2012年01月29日 脚本攻防 我要评论
分享一个不错的iptables脚本在网上闲逛的时候,发现这个不错的iptables脚本,作者不知道是哪位,向原作者来致敬!也分享出来,供大家来参考... 12-01-29

代码如下:

复制代码
代码如下:

#!/bin/sh
#
modprobe ipt_masquerade
modprobe ip_conntrack_ftp
modprobe ip_nat_ftp
iptables -f
iptables -t nat -f
iptables -x
iptables -t nat -x
###########################input键###################################
iptables -p input drop
iptables -a input -m state –state established,related -j accept
iptables -a input -p tcp -m multiport –dports 110,80,25 -j accept
iptables -a input -p tcp -s 192.168.0.0/24 –dport 139 -j accept
#允许内网samba,smtp,pop3,连接
iptables -a input -i eth1 -p udp -m multiport –dports 53 -j accept
#允许dns连接
iptables -a input -p tcp –dport 1723 -j accept
iptables -a input -p gre -j accept
#允许外网vpn连接
iptables -a input -s 192.186.0.0/24 -p tcp -m state –state established,related -j accept
iptables -a input -i ppp0 -p tcp –syn -m connlimit –connlimit-above 15 -j drop
#为了防止dos太多连接进来,那么可以允许最多15个初始连接,超过的丢弃
iptables -a input -s 192.186.0.0/24 -p tcp –syn -m connlimit –connlimit-above 15 -j drop
#为了防止dos太多连接进来,那么可以允许最多15个初始连接,超过的丢弃
iptables -a input -p icmp -m limit –limit 3/s -j log –log-level info –log-prefix “icmp packet in: “
iptables -a input -p icmp -j drop
#禁止icmp通信-ping 不通
iptables -t nat -a postrouting -o ppp0 -s 192.168.0.0/24 -j masquerade
#内网转发
iptables -n syn-flood
iptables -a input -p tcp –syn -j syn-flood
iptables -i syn-flood -p tcp -m limit –limit 3/s –limit-burst 6 -j return
iptables -a syn-flood -j reject
#防止syn攻击 轻量
#######################forward链###########################
iptables -p forward drop
iptables -a forward -p tcp -s 192.168.0.0/24 -m multiport –dports 80,110,21,25,1723 -j accept
iptables -a forward -p udp -s 192.168.0.0/24 –dport 53 -j accept
iptables -a forward -p gre -s 192.168.0.0/24 -j accept
iptables -a forward -p icmp -s 192.168.0.0/24 -j accept
#允许 vpn客户走vpn网络连接外网
iptables -a forward -m state –state established,related -j accept
iptables -i forward -p udp –dport 53 -m string –string “tencent” -m time –timestart 8:15 –timestop 12:30 –days mon,tue,wed,thu,fri,sat -j drop
#星期一到星期六的8:00-12:30禁止qq通信
iptables -i forward -p udp –dport 53 -m string –string “tencent” -m time –timestart 8:15 –timestop 12:30 –days mon,tue,wed,thu,fri,sat -j drop
#星期一到星期六的8:00-12:30禁止qq通信
iptables -i forward -p udp –dport 53 -m string –string “tencent” -m time –timestart 13:30 –timestop 20:30 –days mon,tue,wed,thu,fri,sat -j drop
iptables -i forward -p udp –dport 53 -m string –string “tencent” -m time –timestart 13:30 –timestop 20:30 –days mon,tue,wed,thu,fri,sat -j drop
#星期一到星期六的13:30-20:30禁止qq通信
iptables -i forward -s 192.168.0.0/24 -m string –string “qq.com” -m time –timestart 8:15 –timestop 12:30 –days mon,tue,wed,thu,fri,sat -j drop
#星期一到星期六的8:00-12:30禁止qq网页
iptables -i forward -s 192.168.0.0/24 -m string –string “qq.com” -m time –timestart 13:00 –timestop 20:30 –days mon,tue,wed,thu,fri,sat -j drop
#星期一到星期六的13:30-20:30禁止qq网页
iptables -i forward -s 192.168.0.0/24 -m string –string “ay2000.net” -j drop
iptables -i forward -d 192.168.0.0/24 -m string –string “宽频影院” -j drop
iptables -i forward -s 192.168.0.0/24 -m string –string “zz” -j drop
iptables -i forward -p tcp –sport 80 -m string –string “广告” -j drop
#禁止ay2000.net,宽频影院,zz,广告网页连接 !但中文 不是很理想
iptables -a forward -m ipp2p –edk –kazaa –bit -j drop
iptables -a forward -p tcp -m ipp2p –ares -j drop
iptables -a forward -p udp -m ipp2p –kazaa -j drop
#禁止bt连接
iptables -a forward -p tcp –syn –dport 80 -m connlimit –connlimit-above 15 –connlimit-mask 24
#######################################################################
sysctl -w net.ipv4.ip_forward=1 &>/dev/null
#打开转发
#######################################################################
sysctl -w net.ipv4.tcp_syncookies=1 &>/dev/null
#打开 syncookie (轻量级预防 dos 攻击)
sysctl -w net.ipv4.netfilter.ip_conntrack_tcp_timeout_established=3800 &>/dev/null
#设置默认 tcp 连接痴呆时长为 3800 秒(此选项可以大大降低连接数)
sysctl -w net.ipv4.ip_conntrack_max=300000 &>/dev/null
#设置支持最大连接树为 30w(这个根据你的内存和 iptables 版本来,每个 connection 需要 300 多个字节)
#######################################################################
iptables -i input -s 192.168.0.50 -j accept
iptables -i forward -s 192.168.0.50 -j accept
#192.168.0.50是我的机子,全部放行!
############################完#########################################

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com