WEB常用iptables规则

规则:

iptables --delete-chain
iptables  --flush
iptables  -P INPUT DROP    #1
iptables  -P FORWARD DROP  #1
iptables  -P OUTPUT DROP   #1
iptables  -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #2
iptables  -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT #3
iptables  -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT #3
iptables  -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT  #3
iptables  -A INPUT -p tcp -m tcp --dport 873 -j ACCEPT #3
iptables  -A INPUT -i lo -j ACCEPT #4
iptables  -A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT #允许ping别人
iptables  -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT  #5
iptables  -A INPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT #5
iptables  -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #6
iptables  -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT #7
iptables  -A OUTPUT -o lo -j ACCEPT #4
iptables  -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT #8
iptables  -A OUTPUT -p tcp -m tcp --dport 25 -j ACCEPT #9
iptables  -A OUTPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT  #10
iptables  -A OUTPUT -p icmp -m icmp --icmp-type 11 -j ACCEPT #10
#11
iptables -N syn-flood
iptables -A syn-flood -p tcp -m limit --limit 3/sec --limit-burst 6 -j RETURN
iptables -A syn-flood -j REJECT --reject-with icmp-port-unreachable

iptables-save>/etc/sysconfig/iptables
service iptables restart

说明:

#1、设置INPUT,FORWARD,OUTPUT链默认target为DROP,也就是外部与服务器不能通信。
#2、设置当连接状态为RELATED和ESTABLISHED时,允许数据进入服务器。
#3、设置外部客户端连接服务器端口80,22,21,873。
#4、允许内部数据循回。
#5、允许外部ping服务器 。
#6、设置状态为RELATED和ESTABLISHED的数据可以从服务器发送到外部。
#7、允许服务器使用外部dns解析域名。
#8、设置服务器连接外部服务器端口80。
#9、允许服务器发送邮件。
#10、允许从服务器ping外部。
#11、抵御洪水攻击

限制单位时间内连接数

iptables -N syn-flood
iptables -A FORWARD -p tcp --syn -j syn-flood
iptables -A INPUT -p tcp --syn -j syn-flood
iptables -A syn-flood -p tcp --syn -m limit --limit 3/s --limit-burst 1 -j ACCEP
iptables -A syn-flood -j DROP
iptables -A INPUT -i eth0 -p tcp ! --syn -m state --state NEW -j DROP
iptables -A INPUT -p tcp --syn -m state --state NEW -j DROP

参考文章

  1. http://blog.sina.com.cn/s/blog_6915bcb101013st7.html
  2. https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值