免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4971 | 回复: 10

[网络管理] iptables + tc 做限速的问题 [复制链接]

论坛徽章:
0
发表于 2010-12-30 11:20 |显示全部楼层
本帖最后由 nomyself 于 2011-01-02 16:25 编辑

4M的光纤,内网30-40台机器通过linux nat上网。eth0内,eth1外。所有上传数据都直接走默认的
tc配置如下。

tc qdisc add dev eth0 root handle 1:0 htb default 13
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 4Mbit ceil 4Mbit
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 2Mbit ceil 4Mbit prio 1
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 1Mbit ceil 2Mbit prio 2
tc class add dev eth0 parent 1:1 classid 1:13 htb rate 1Mbit ceil 1Mbit prio 3
tc qdisc add dev eth0 parent 1:11 handle 110: sfq perturb 10
tc qdisc add dev eth0 parent 1:12 handle 120: sfq perturb 10
tc qdisc add dev eth0 parent 1:13 handle 130: sfq perturb 10
tc filter add dev eth0 parent 1:0 protocol ip prio 1 handle 1 fw classid 1:11
tc filter add dev eth0 parent 1:0 protocol ip prio 2 handle 2 fw classid 1:12
tc filter add dev eth0 parent 1:0 protocol ip prio 3 handle 7 fw classid 1:13

tc qdisc add dev eth1 root handle 1:0 htb default 13
tc class add dev eth1 parent 1:0 classid 1:1 htb rate 4Mbit ceil 4Mbit
tc class add dev eth1 parent 1:1 classid 1:11 htb rate 2Mbit ceil 4Mbit prio 1
tc class add dev eth1 parent 1:1 classid 1:12 htb rate 1Mbit ceil 2Mbit prio 2
tc class add dev eth1 parent 1:1 classid 1:13 htb rate 1Mbit ceil 2Mbit prio 3
tc qdisc add dev eth1 parent 1:11 handle 110: sfq perturb 10
tc qdisc add dev eth1 parent 1:12 handle 120: sfq perturb 10
tc qdisc add dev eth1 parent 1:13 handle 130: sfq perturb 10
tc filter add dev eth1 parent 1:0 protocol ip handle 11 fw classid 1:11
tc filter add dev eth1 parent 1:0 protocol ip handle 12 fw classid 1:12
tc filter add dev eth1 parent 1:0 protocol ip handle 17 fw classid 1:13


iptables 打mark:

对下载进行分类
iptables -t mangle -A POSTROUTING -p tcp --sport xxx -j MARK --set-mark x
对上传进行分类
iptables -t mangle -A PREROUTING -p tcp --dport xxx -j MARK --set-mark x

问题:
上传数据全部走 1:13, iptables -v -n --list 查看打的标正常

class htb 1:11 parent 1:1 leaf 110: prio 1 rate 2000Kbit ceil 4000Kbit burst 1849b cburst 2099b
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 0 borrowed: 0 giants: 0
tokens: 7226 ctokens: 4101

class htb 1:1 root rate 4000Kbit ceil 4000Kbit burst 2099b cburst 2099b
Sent 1316987 bytes 13003 pkt (dropped 0, overlimits 0 requeues 0)
rate 73040bit 113pps backlog 0b 0p requeues 0
lended: 150 borrowed: 0 giants: 0
tokens: 3898 ctokens: 3898

class htb 1:13 parent 1:1 leaf 130: prio 3 rate 1000Kbit ceil 2000Kbit burst 1724b cburst 1849b
Sent 1316987 bytes 13003 pkt (dropped 0, overlimits 0 requeues 0)
rate 73040bit 113pps backlog 0b 0p requeues 0
lended: 12850 borrowed: 150 giants: 0
tokens: 12664 ctokens: 6820

class htb 1:12 parent 1:1 leaf 120: prio 2 rate 1000Kbit ceil 2000Kbit burst 1724b cburst 1849b
Sent 0 bytes 0 pkt (dropped 0, overlimits 0 requeues 0)
rate 0bit 0pps backlog 0b 0p requeues 0
lended: 0 borrowed: 0 giants: 0
tokens: 13476 ctokens: 7226

论坛徽章:
0
发表于 2011-01-02 16:23 |显示全部楼层
数据全部走默认的分类,怀疑打表有问题。测试:

iptables -t mangle -A PREROUTING -p tcp --dport 443 -j MARK --set-mark 12
iptables -t mangle -A PREROUTING -p tcp --dport 443 -j RETURN

使用gmail上传近9M的附件,iptables --list -v -n -t mangle 查看数据
7433   10M MARK       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0          tcp dpt:443 MARK set 0xc
7433   10M RETURN     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0          tcp dpt:443

说明打表的话就正确的,排除标记问题...

论坛徽章:
0
发表于 2011-01-02 19:04 |显示全部楼层
回复 2# nomyself


    你好,没太明白RETURN是什么意思,man了一下没看明白,能帮我解释一下吗?谢谢

论坛徽章:
0
发表于 2011-01-03 11:38 |显示全部楼层
回复 3# inknk

RETURN : 返回上一个链,这里触发mangle表中的PREROUTING或POSTROUTING链的默认策略即ACCEPT。用在这的好处就是避免遍历规则。

今天测试使用imq来做流量限制。

发现使用u32打标的话就正常了

tc filter add dev eth1 parent 1:0 protocol ip prio 1 u32 match ip dport 22 0xffff classid 1:11

以上的u32规则与
iptables -t mangle -A PREROUTING -p tcp --dport 22 -j MARK --set-mark 11 不是一样的意思?

论坛徽章:
0
发表于 2011-01-03 12:04 |显示全部楼层
额.....
是不是匹配到 iptables -t mangle -A PREROUTING -p tcp --dport 443 -j MARK --set-mark 12 这条规则的数据还要继续往下匹配??
我的理解是:对于一个数据包来说,只要匹配到一条规则就会停止,然后进入下一条链。不知道这样对不对?

论坛徽章:
0
发表于 2011-01-03 12:05 |显示全部楼层
回复 4# nomyself


    额.....
是不是匹配到 iptables -t mangle -A PREROUTING -p tcp --dport 443 -j MARK --set-mark 12 这条规则的数据还要继续往下匹配??
我的理解是:对于一个数据包来说,只要匹配到一条规则就会停止,然后进入下一条链。不知道这样对不对?

论坛徽章:
0
发表于 2011-01-03 13:25 |显示全部楼层
回复  nomyself


    额.....
是不是匹配到 iptables -t mangle -A PREROUTING -p tcp --dport 443 - ...
inknk 发表于 2011-01-03 12:05


对,做个试验,我在
iptables -t mangle -A POSTROUTING -p tcp --sport 80 -j MARK --set-mark 2后面加了条
iptables -t mangle -A POSTROUTING -p tcp --sport 80 -j LOG --log-prefix='=TEST='
下面是日志记录的内容,说明是会往下走的,在RETURN后面加入LOG记录的话就不会有下面的记录。
Jan  3 13:19:49 gateway kernel: =TEST=IN= OUT=eth0 SRC=112.90.139.97 DST=192.168.1.133

论坛徽章:
0
发表于 2011-01-04 14:35 |显示全部楼层
回复 7# nomyself


    你的意思是匹配到一条规则后还要继续往下匹配吧?
    我的意思是匹配到一条规则后就不往下匹配了,而是进入下一个链。
    比如某数据包在PREROUTING链中匹配到一条打标记的规则,然后就会跳到FORWARD链去,即使PREROUTING 链后面还要规则,也不匹配了

论坛徽章:
0
发表于 2011-05-11 16:51 |显示全部楼层
回复 1# nomyself

这三条是什么意思
tc qdisc add dev eth0 parent 1:11 handle 110: sfq perturb 10
tc qdisc add dev eth0 parent 1:12 handle 120: sfq perturb 10
tc qdisc add dev eth0 parent 1:13 handle 130: sfq perturb 10

论坛徽章:
381
CU十二周年纪念徽章
日期:2014-01-04 22:46:58CU大牛徽章
日期:2013-03-13 15:32:35CU大牛徽章
日期:2013-03-13 15:38:15CU大牛徽章
日期:2013-03-13 15:38:52CU大牛徽章
日期:2013-03-14 14:08:55CU大牛徽章
日期:2013-04-17 11:17:19CU大牛徽章
日期:2013-04-17 11:17:32CU大牛徽章
日期:2013-04-17 11:17:37CU大牛徽章
日期:2013-04-17 11:17:42CU大牛徽章
日期:2013-04-17 11:17:47CU大牛徽章
日期:2013-04-17 11:17:52CU大牛徽章
日期:2013-04-17 11:17:56
发表于 2011-05-11 17:03 |显示全部楼层
回复 9# 20040925


    建立队列,具体的去http://lartc.org下载中文文档研究
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP