make menuconfigNetworking support -> Networking Options -> Network packet filtering framework -> Core Netfilter Configuration<M> Netfilter connection tracking support<M> \”lawyer7\” match support<M> \”string\” match support<M> \”time\” match support<M> \”iprange\” match support<M> \”connlimit\” match support<M> \”state\” match support<M> \”conntrack\” connection match support<M> \”mac\” address match support<M> \”multiport\” Multiple port match supportNetworking support -> Networign options -> Network packet filtering framework -> IP:Netfiltr Configuration<M> IPv4 connection tracking support (required for NAT)<M> Full NAT<M> MASQUERADE target support<M> NETMAP target support<M> REDIRECT target support
在Networking support中选择 Networking options
查找Network packet filtering framework(Netfilter)–>Core Netfiler Configrationg–>Netfilter connection tracking support(NEW),”layer7″ match support(NEW),”time” match support(NEW),”iprange”
#在eth0网卡上创建一个根队列规则,队列规则的算法使用htb,default 2表示指定一个默认类别编号,默认的流量控制策略,如果ip没有在后面的filter中被匹配到就都是有这个策略tc qdisc add dev eth0 root handle 1:0 htb default 2#在eth0网卡上定义一个类,prant 1:0中的1对应根队列规则中的handle 1:0,classid 1:2表示当前这个类的标识,用于应用在后面的得到filter中,rate 200kbsp表示带宽为200KB/s,ceil 200kbps表示最大带宽也为200KB/s,prio 2是优先级tc class add dev eth0 parent 1:0 classid 1:2 htb rate 200kbps ceil 200kbps prio 2tc class add dev eth0 parent 1:0 classid 1:3 htb rate 500kbps ceil 500kbps prio 2#将两个类的默认的fifq队列规则改为sfqtc qdisc add dev eth0 parent 1:2 handle 20 sfqtc qdisc add dev eth0 parent 1:3 handle 30 sfq#在网卡eth0上的1:0节点(对应qdisc中的handle 1:0)添加一个u32过滤规则,优先级为1,凡是目标地址是10.0.0.100的数据包都使用1:2类(对应classid为1:2的类)tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip dst 10.0.0.100 flowid 1:2tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip dst 10.0.0.101 flowid 1:3
如果还有其他用户例如用户C和D的ip是102、103,要求的下载带宽也要求500那么在加入
复制代码
代码如下:
tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip dst 10.0.0.102 flowid 1:3tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip dst 10.0.0.103 flowid 1:3