防火墙 – 当服务器从中接收到大量数据时禁止IP

我需要的 :

根据每个时间段的请求量添加丢弃规则有很多结果,但我需要在一段时间内从特定地址接收字节数.

我调查的内容

我看了iptables:对于第一种情况,我看到了一个专用的match.我也看到了quota 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_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.

有关详细信息,请阅读文档

相关文章

Linux中的ARP防火墙主要用于防御ARP欺骗攻击,其效果取决于多...
insmod和modprobe加-f参数导致Invalid module format错误 这...
将ArchLinux安装到U盘 几个月前入门Arch的时候上网搜了不少安...
1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...