在每一圈的时间内,通过请求数量增加一个丢弃规则的结果是很多的,但是我需要在一段时间内从一个特定的地址接收字节数量。
我看着iptables:对于第一个案例,我看到了一个专门的匹配 。 我也看到了配额匹配,但数据统计是全球跟踪的。
我不知道如何混合两条规则来跟踪每个IP接收到的数据。
我知道跟踪每个IP的字节数可以使用大量的内存,这就是为什么我也想保持短暂的时间。
我可以接受其他方法,只要有一个详细的例子。
您可以使用具有超时和计数器选项的IPSET。 这将是这样的:
#create ipset for accounting with default lifetime 300 secs ipset create IP_QUOTA_SET hash:ip timeout 300 counters #create separated rule chain iptables --new-chain PER_IP_QOUTING #send packets to chain iptables -t filter -A INPUT \ -i <in-iface> --dst <ip> \ -p tcp --dport <dstport> \ -j PER_IP_QUOTING #if ip doesn't exist in the set, add it iptables -t filter -A PER_IP_QUOTING \ -m set ! --match-set IP_QUOTA_SET src \ -j SET --add-set IP_QUOTA_SET src --timeout 300 #if packet exists in the set, check bytes #if byte counter > quota then close connection #by sending of tcp-reset packet. iptables -t filter -A PER_IP_QUOTING \ -m set --match-set IP_QUOTA_SET src \ --bytes-gt 1000 -j REJECT --reject-with tcp-rst #pass other packets (for debug purpose) iptables -t filter -A PER_IP_QUOTING \ -j RETURN
在这种情况下,您可以检查列表并使用ipset命令进行编辑。 用计数器和超时显示当前列表:ipset list IP_QUOTA_SET。
详情请阅读文档。