use*_*570 5 firewall denial-of-service linux-networking
通过每圈时间的请求量添加删除规则有很多结果,但我需要在一段时间内删除来自特定地址的接收字节数。
我查看了 iptables :对于第一种情况,我看到了一个专用match。我也看到了配额匹配,但是数据计数是全局跟踪的。
我不知道如何混合这两个规则来跟踪每个 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_QUOTING
#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
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您可以检查该列表并通过 ipset 命令对其进行编辑。显示带有计数器和超时的当前列表:ipset list IP_QUOTA_SET。
有关详细信息,请阅读文档。
归档时间: |
|
查看次数: |
487 次 |
最近记录: |