LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1838|回复: 4

请教!Linux中的流量控制

[复制链接]
发表于 2009-5-17 18:02:32 | 显示全部楼层 |阅读模式
环境:三网卡,eth0连接ADSL,eth1连接局域网,eth2暂未启用,要限制192.168.0.155的上传带宽
我是这样做的:
iptables -t mangle -A PREROUTING -i eth1 -s 192.168.0.155/32 -j MARK --set-mark 4
tc qdisc add dev eth0 root handle 1:0 htb default 10
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 4Mbit burst 15k
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 4Mbit burst 15k
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 4kbit ceil 4kbit burst 15k  prio 4
tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
tc filter add dev eth0 parent 1:0 protocol ip prio 4 handle 4 fw classid  1:20
问题:
iptables打标之后tc不起作用,敢问何解?

这是mangle表
[root@x100plus ~]# iptables -v -t mangle -nL
Chain PREROUTING (policy ACCEPT 589K packets, 136M bytes)
pkts bytes target     prot opt in     out     source               destination         
2325  254K MARK       all  --  eth1   *       192.168.0.155        0.0.0.0/0           MARK set 0x4

Chain INPUT (policy ACCEPT 476K packets, 91M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 113K packets, 45M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 463K packets, 94M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 576K packets, 138M bytes)
pkts bytes target     prot opt in     out     source               destination

这是tc qdisc表
[root@x100plus ~]# tc -s -d qdisc
qdisc htb 1: dev eth0 r2q 10 default 10 direct_packets_stat 0 ver 3.17
Sent 935648 bytes 4596 pkts (dropped 0, overlimits 0 requeues 0)
qdisc sfq 10: dev eth0 parent 1:10 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 935648 bytes 4596 pkts (dropped 0, overlimits 0 requeues 0)
qdisc sfq 20: dev eth0 parent 1:20 limit 128p quantum 1514b flows 128/1024 perturb 10sec
Sent 0 bytes 0 pkts (dropped 0, overlimits 0 requeues 0)
qdisc pfifo_fast 0: dev eth1 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 168854951 bytes 676186 pkts (dropped 0, overlimits 0 requeues 0)
qdisc pfifo_fast 0: dev eth2 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 0 bytes 0 pkts (dropped 0, overlimits 0 requeues 0)
qdisc pfifo_fast 0: dev eth3 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 0 bytes 0 pkts (dropped 0, overlimits 0 requeues 0)
qdisc pfifo_fast 0: dev ppp0 bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
Sent 43985124 bytes 143910 pkts (dropped 0, overlimits 0 requeues 0)

eth0网卡的class状态
[root@x100plus ~]# tc -s -d class ls dev eth0
class htb 1:1 root rate 4Mbit ceil 4Mbit burst 15Kb/8 mpu 0b overhead 0b cburst 2099b/8 mpu 0b overhead 0b level 7
Sent 973430 bytes 4754 pkts (dropped 0, overlimits 0 requeues 0)
rate 1361bit 5pps
lended: 0 borrowed: 0 giants: 0
tokens: 31261 ctokens: 4104

class htb 1:10 parent 1:1 leaf 10: prio 0 quantum 50000 rate 4Mbit ceil 4Mbit burst 15Kb/8 mpu 0b overhead 0b cburst 2099b/8 mpu 0b overhead 0b level 0
Sent 973430 bytes 4754 pkts (dropped 0, overlimits 0 requeues 0)
rate 1361bit 5pps
lended: 4754 borrowed: 0 giants: 0
tokens: 31261 ctokens: 4104

class htb 1:20 parent 1:1 leaf 20: prio 4 quantum 1000 rate 4Kbit ceil 4Kbit burst 15Kb/8 mpu 0b overhead 0b cburst 1599b/8 mpu 0b overhead 0b level 0
Sent 0 bytes 0 pkts (dropped 0, overlimits 0 requeues 0)
lended: 0 borrowed: 0 giants: 0
tokens: 31457280 ctokens: 3276800
发表于 2009-5-20 16:48:04 | 显示全部楼层

你做网桥了吗?

如题!两个网卡做网桥了吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-5-23 20:58:53 | 显示全部楼层
没做,需要做吗?
回复 支持 反对

使用道具 举报

发表于 2009-5-25 08:35:02 | 显示全部楼层
我进行了一下分析:
你可以测试一下,看看能不能成功:
1. 你连接ADSL后,用ipconfig 查看,会有一个ppp0,好像是这个,是不是应该在ppp0上来做流量控制(我自己想象的,具体你可以测试一下)。
2.如果1不行,你试着指定一下网卡,添加一个-m physdev --physdev-in eth1 试试
仅供参考,祝你好运!
回复 支持 反对

使用道具 举报

发表于 2010-1-12 14:44:42 | 显示全部楼层
使用IMQ就没有这些鸟毛病的,不用管网卡接口名称
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表