centos – 添加新规则时iptables超出配额

前端之家收集整理的这篇文章主要介绍了centos – 添加新规则时iptables超出配额前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在Centos 7上运行了iptables,使用版本v1.4.21,但也在v1.6.0上进行了测试(请注意,我没有重建内核,因为它说我不再需要扩展).

我设置了一个配额,它被使用:

@H_301_3@# iptables -nvx -L 192.168.2.5 Chain 192.168.2.5 (2 references) pkts bytes target prot opt in out source destination 3639 3999378 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 4000000 bytes 142 175468 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 #

然后,当我向此链添加任何其他规则时,现有规则“重置”字节使用情况并再次使用配额:

@H_301_3@# iptables -I 192.168.2.5 -m quota --quota 1000 -j ACCEPT # iptables -nvx -L 192.168.2.5 Chain 192.168.2.5 (2 references) pkts bytes target prot opt in out source destination 2 168 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 1000 bytes 7239 7998334 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 4000000 bytes 890 387931 DROP all -- * * 0.0.0.0/0 0.0.0.0/0

即使未超出此限制,此行为也始终会将配额量添加到规则中,即使我正在影响其他规则:

@H_301_3@# iptables -nvx -L 192.168.2.5 Chain 192.168.2.5 (2 references) pkts bytes target prot opt in out source destination 379 67755 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 4000000 bytes 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 # iptables -I 192.168.2.5 -m quota --quota 1000 -j ACCEPT # iptables -nvx -L 192.168.2.5 Chain 192.168.2.5 (2 references) pkts bytes target prot opt in out source destination 2 168 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 1000 bytes 379 67755 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 4000000 bytes 0 0 DROP all -- * * 0.0.0.0/0 0.0.0.0/0 # iptables -nvx -L 192.168.2.5 Chain 192.168.2.5 (2 references) pkts bytes target prot opt in out source destination 11 924 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 1000 bytes 4159 4066453 ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 quota: 4000000 bytes 315 190056 DROP all -- * * 0.0.0.0/0 0.0.0.0/0

这似乎是一个错误,也许与this one有关.

有任何想法吗?
我的一个解决方法是自己捕获字节并将它们添加到新规则的配额中.当它已经超过时,它运行良好,但如果没有,由于读取,计算,删除添加之间的差距,我可能会错过字节.

@H_404_19@
阅读您链接和测试的其他问题,我只能得出结论,配额模块不是很有用:每当有变化时重置.

这肯定是为什么还有一个名为quota2的模块!它不是iptables的一部分,而是xtables-addons的一部分.在Debian中,它可以使用xtables-addons-dkms进行安装.我想你必须自己在CentOS7中编译它.

手册页的三个摘录(可在此处找到:xtables-addons.8)

The value of the counter can be read and reset through procfs,thereby making this match a minimalist accounting tool.

.

–name name
Assign the counter a specific name. This option must be present,

配额显示在/ proc / net / xt_quota / name中,并且是可读/写的

–quota iq
Specify the initial quota for this counter. If the counter already exists,it is not reset.

这意味着必须使用iptables之外的一些逻辑(例如,如果必须重新启动服务器,则保存剩余的配额并在启动时恢复),但这肯定会解决您的问题.

猜你在找的CentOS相关文章