从iptables和ipset命令添加IP地址时,ipset的行为会有所不同

我有一个列表,下面的命令创build

ipset create foo hash:ip maxelem 40000000 timeout 180 

这是如何虚空看起来像

 #ipset list foo Name: foo Type: hash:ip Revision: 1 Header: family inet hashsize 1024 maxelem 40000000 timeout 180 Size in memory: 16504 References: 0 Members: 

然后我添加了一个/ 16子网,这意味着65535个IP地址。 正如我们可以看到下面的命令,哈希大小dynamic改变和IP地址添加成功。

 #ipset add foo 192.168.0.0/16 #ipset list foo | head -10 Name: foo Type: hash:ip Revision: 1 Header: family inet hashsize 32768 maxelem 40000000 timeout 180 Size in memory: 2925208 References: 0 Members: 192.168.165.92 timeout 175 192.168.241.240 timeout 175 192.168.84.49 timeout 175 # ipset list foo | wc -l 65543 

现在我正在销毁这个集合,并使用上面的相同命令重新创build,以便我再次将散列大小均衡为1024。 然后我将下面的规则添加到iptables中,并用hping3发送随机包

 iptables -A PREROUTING -t raw -j SET --add-set foo src hping3 --flood --rand-source <server-ip> 

当攻击继续时,它看起来iptables不能在一些点以后增加更多IP地址。 哈希大小保持不变

 # ipset list foo | wc -l 12295 # ipset list foo | head -10 Name: foo Type: hash:ip Revision: 1 Header: family inet hashsize 1024 maxelem 40000000 timeout 180 Size in memory: 262264 References: 1 Members: 5.125.171.17 timeout 174 92.5.220.202 timeout 174 164.124.160.24 timeout 174 

如果我通过手动增加hashsize来重复这个testing,它会使iptables增加更多的IP地址。

我使用以下版本在CentOS 7上做了这个testing

 kernel 3.15.9 ipset 6.19 iptables 1.4.21 

我的问题是,这是什么原因? 这是安全措施还是什么?

它看起来像iptables不能添加更多的IP地址后点

这是一个ipset哈希表的预期行为,如介绍手册中所述:

…当iptables / ip6tables的SET目标添加的条目,那么散列大小是固定的,并且该集合将不会被复制,即使新条目不能被添加到该集合。

没有理由给出,但有人可能会猜测,防止防火墙潜在地声称无限量的内存是一个好东西TM