大网数据广告活动
服务器运维问答

ipset behave differently when adding IP address from iptables and ipset command

· 52CE 我爱测

I have a list that created below command ipset create foo hash:ip maxelem 40000000 timeout 180 This is how empty foo look like #ipset list foo Name: foo Type: hash:ip Revision: 1 Header: family inet hashsize 1024 maxelem 40000000…

问题原文

原帖链接 · ibrahim · CC BY-SA 3.0

I have a list that created below command

ipset create foo hash:ip maxelem 40000000 timeout 180

This is how empty foo look like

#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:

Then I added a /16 subnet which means 65535 IP addresses. As we can see below commands, hashsize changed dynamically and IP addresses added succesfully.

#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

Now I am destroying this set and creating again with same command above so that I equalize hashsize to 1024 again. Then I added below rule to iptables and sending random packages with hping3

iptables -A PREROUTING -t raw -j SET --add-set foo src

hping3  --flood  --rand-source <server-ip>

While attack continues, it looks iptables can not add more IP addresses after some point. And hashsize stays same

# 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

If I repeat this test by increasing hashsize by hand, it makes iptables can add more IP addresses.

I did this test on CentOS 7 with below versions

kernel 3.15.9
ipset 6.19
iptables 1.4.21

My question is that what is the reason of this cituation? Is this a security precaution or something?

已采纳解答

原帖链接 · HBruijn · CC BY-SA 3.0

it looks like iptables can not add more IP addresses after some point

That is expected behaviour for an ipset hashtable as described in the manual in the Introduction:

... When entries added by the SET target of iptables/ip6tables, then the hash size is fixed and the set won't be duplicated, even if the new entry cannot be added to the set.

No reason is given, but one might speculate that preventing a firewall from potentially claiming an unlimited amount of memory is a Good ThingTM ....

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。