我可以创建规则来限制整个子网,或者用tc和htb限制单个ip地址。我正在寻找使用CIDR范围保持一些优雅的东西。
所讨论的机器都在运行CentOS 7,我一直试图使用tc + htb来实现这一点,但是如果有更好的方法,我会向其他工具开放。
我的目标是限制一个CIDR范围,并为每个源ip地址指定单独的限制。
例如,将192.168.1.0/24至100 24/S设置为全局限制,192.168.1.0/24中的每个源ip的个人上传限制为10 24/S,但不得超过。
下面是我为每个ip所做的工作示例(如果可能的话,希望简化过程):
这些步骤只需要执行一次:
Create initial HTB qdisc:
# tc qdisc add dev eth0 root handle 1: htb default 12
Create root class:
# tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
These steps must be performed for each IP in the CIDR range using current method (what I am looking to hopefully improve):
A class must be added for each source ip:
# tc class add dev eth0 parent 1:1 classid 1:10 htb rate 10mbit ceil 100mbit
# tc class add dev eth0 parent 1:1 classid 1:11 htb rate 10mbit ceil 100mbit
# tc class add dev eth0 parent 1:1 classid 1:12 htb rate 10mbit ceil 100mbit
A filter must be created for each source ip:
# tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.1.2 flowid 1:10
# tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.1.3 flowid 1:11
也许没有优雅的方法来做到这一点,但是任何的建议/建议都会受到极大的赞赏。我已经浏览过几个在线指南,比如http://lartc.org。谢谢。
发布于 2015-12-03 09:21:45
我认为您可以尝试使用散列,给每个ip一个桶,以便为每个ip提供相同数量的pps。您也应该使用sfq,因为htb是不公平的。
tc qdisc add dev eth0 root handle 1: htb default 12
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
# Here, you want a fair qdisc
tc qdisc add dev eth0 parent 1:1 handle 101: sfq perturb 10
# Put a range in the filter
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.1.0/24 flowid 1:1
# Create 254 bucket, each ip src will be attached to one bucket
tc filter add dev eth0 parent 1:1 protocol ip handle 10 flow hash keys nfct-src divisor 254
发布于 2020-11-27 08:54:02
嗨,你可以在这里找到:Linux防火墙标记分类器(Tc)升级到Debian 9-内核4.19后无法工作工作配置为您的任务。
布尔尼
https://serverfault.com/questions/705432
复制相似问题