本教程介绍使用queue tree开启ros的流控功能
- 介绍两种流量整形,第一种适用于家庭普通用户,第二种适用经常有于BT PT等大流量应用占用带宽的用户
1、为DNS、web等小包流量设置更高优先级,提高网页响应速度,适合一般用户使用
1 2 3 4 5 6 7 8 9 10
| /queue type add fq-codel-flows=128 fq-codel-interval=30ms fq-codel-limit=128 fq-codel-memlimit=4096.0KiB fq-codel-quantum=512 fq-codel-target=3ms kind=fq-codel name=Fq_Codel_Dns_Up /queue type add fq-codel-flows=256 fq-codel-interval=30ms fq-codel-limit=128 fq-codel-memlimit=8.0MiB fq-codel-quantum=512 fq-codel-target=3ms kind=fq-codel name=Fq_Codel_Dns_Down /queue type add fq-codel-flows=512 fq-codel-interval=50ms fq-codel-limit=512 fq-codel-memlimit=8.0MiB fq-codel-quantum=512 fq-codel-target=5ms kind=fq-codel name=Fq_Codel_Small_Up /queue type add fq-codel-flows=512 fq-codel-interval=50ms fq-codel-limit=512 fq-codel-memlimit=16.0MiB fq-codel-quantum=512 fq-codel-target=5ms kind=fq-codel name=Fq_Codel_Small_Down /queue type add fq-codel-flows=512 fq-codel-interval=50ms fq-codel-limit=2048 fq-codel-memlimit=64.0MiB fq-codel-quantum=1400 fq-codel-target=5ms kind=fq-codel name=Fq_Codel_Web_Up /queue type add fq-codel-flows=1024 fq-codel-interval=50ms fq-codel-limit=4096 fq-codel-memlimit=128.0MiB fq-codel-quantum=1500 fq-codel-target=5ms kind=fq-codel name=Fq_Codel_Web_Down /queue type add fq-codel-flows=1024 fq-codel-interval=100ms fq-codel-limit=8192 fq-codel-memlimit=128.0MiB fq-codel-quantum=1400 fq-codel-target=8ms kind=fq-codel name=Fq_Codel_Stream_Up /queue type add fq-codel-flows=2048 fq-codel-interval=100ms fq-codel-limit=10240 fq-codel-memlimit=256.0MiB fq-codel-quantum=1500 fq-codel-target=8ms kind=fq-codel name=Fq_Codel_Stream_Down /queue type add fq-codel-flows=2048 fq-codel-interval=100ms fq-codel-limit=10240 fq-codel-memlimit=128.0MiB fq-codel-quantum=1400 fq-codel-target=20ms kind=fq-codel name=Fq_Codel_Nomark_Up /queue type add fq-codel-flows=4096 fq-codel-interval=100ms fq-codel-limit=10240 fq-codel-memlimit=256.0MiB fq-codel-quantum=1500 fq-codel-target=15ms kind=fq-codel name=Fq_Codel_Nomark_Down
|
自行修改桥的名称(bridge1)及pppoe拨号口(pppoe-out1)的名称
注:下行Down,配置了bridge则用beidge,未配置则用lan网卡
1 2 3 4 5
| /queue tree add bucket-size=0.005 name=Dns-packet-Down packet-mark=Dns-packet parent=bridge1 priority=1 queue=Fq_Codel_Dns_Down /queue tree add bucket-size=0.01 name=Small-packet-Down packet-mark=Small-packet parent=bridge1 priority=2 queue=Fq_Codel_Small_Down /queue tree add bucket-size=0.03 name=Web-packet-Down packet-mark=Web-packet parent=bridge1 priority=3 queue=Fq_Codel_Web_Down /queue tree add bucket-size=0.06 name=Stream-Packet-Down packet-mark=Stream-packet parent=bridge1 priority=4 queue=Fq_Codel_Stream_Down /queue tree add bucket-size=0.1 name=Nomark-Packet-Down packet-mark=no-mark parent=bridge1 priority=6 queue=Fq_Codel_Nomark_Down
|
注:上行UP,接口直接用网卡wan
1 2 3 4 5
| /queue tree add bucket-size=0.005 name=Dns-packet-Up packet-mark=Dns-packet parent=wan priority=1 queue=Fq_Codel_Dns_Up /queue tree add bucket-size=0.01 name=Small-packet-Up packet-mark=Small-packet parent=wan priority=2 queue=Fq_Codel_Small_Up /queue tree add bucket-size=0.03 name=Web-packet-Up packet-mark=Web-packet parent=wan priority=3 queue=Fq_Codel_Web_Up /queue tree add bucket-size=0.06 name=Stream-Packet-Up packet-mark=Stream-packet parent=wan priority=4 queue=Fq_Codel_Stream_Up /queue tree add bucket-size=0.1 name=Nomark-Packet-Up packet-mark=no-mark parent=wan priority=6 queue=Fq_Codel_Nomark_Up
|
- ipv4防火墙中使用mangle标记不同类型的流量(可直接复制,不用修改)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| /ip firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ip firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp /ip firewall mangle add action=change-mss chain=output comment=MSS new-mss=clamp-to-pmtu protocol=tcp tcp-flags=syn /ip firewall mangle add action=change-mss chain=forward new-mss=clamp-to-pmtu protocol=tcp tcp-flags=syn /ip firewall mangle add action=mark-routing chain=prerouting comment=Telegram dst-address-list=Telegram dst-address-type=!local new-routing-mark=SingBox_V4 passthrough=no /ip firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ip firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp /ip firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 connection-bytes=0-256k passthrough=no /ip firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Stream-packet packet-mark=no-mark passthrough=no /ip firewall mangle add action=mark-packet chain=forward new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ip firewall mangle add action=mark-packet chain=forward new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp /ip firewall mangle add action=mark-packet chain=forward new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ip firewall mangle add action=mark-packet chain=forward new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp /ip firewall mangle add action=mark-packet chain=forward new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 connection-bytes=0-256k passthrough=no /ip firewall mangle add action=mark-packet chain=forward new-packet-mark=Stream-packet packet-mark=no-mark passthrough=no
|
- ipv6防火墙中使用mangle标记不同类型的流量(可直接复制,不用修改)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| /ipv6 firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp /ipv6 firewall mangle add action=change-mss chain=output comment=MSS new-mss=clamp-to-pmtu protocol=tcp tcp-flags=syn /ipv6 firewall mangle add action=change-mss chain=forward new-mss=clamp-to-pmtu protocol=tcp tcp-flags=syn /ipv6 firewall mangle add action=mark-routing chain=prerouting comment=Telegram dst-address-list=Telegram dst-address-type=!local new-routing-mark=SingBox_V6 passthrough=no /ipv6 firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ipv6 firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 passthrough=no /ipv6 firewall mangle add action=mark-packet chain=prerouting new-packet-mark=Stream-packet packet-mark=no-mark passthrough=no /ipv6 firewall mangle add action=mark-packet chain=forward new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=forward new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp /ipv6 firewall mangle add action=mark-packet chain=forward new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ipv6 firewall mangle add action=mark-packet chain=forward new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=forward new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 connection-bytes=0-256k passthrough=no /ipv6 firewall mangle add action=mark-packet chain=forward new-packet-mark=Stream-packet packet-mark=no-mark passthrough=no
|
2、为宽带及特定服务设定上传下载限速,并按服务设定优先级,主要适合PT、BT用户,PCDN也可参考使用,一般家用用第一种即可
- 添加queue type,为每个类型的流量添加一个type
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| /queue type set 1 pfifo-limit=256 add fq-codel-flows=128 fq-codel-interval=30ms fq-codel-limit=128 fq-codel-memlimit=4096.0KiB fq-codel-quantum=512 fq-codel-target=3ms kind=fq-codel name=Fq_Codel_Dns_Up add fq-codel-flows=256 fq-codel-interval=30ms fq-codel-limit=128 fq-codel-memlimit=8.0MiB fq-codel-quantum=512 fq-codel-target=3ms kind=fq-codel name=Fq_Codel_Dns_Down add fq-codel-flows=512 fq-codel-interval=50ms fq-codel-limit=512 fq-codel-memlimit=8.0MiB fq-codel-quantum=512 kind=fq-codel name=Fq_Codel_Small_Up add fq-codel-flows=512 fq-codel-interval=50ms fq-codel-limit=512 fq-codel-memlimit=16.0MiB fq-codel-quantum=512 kind=fq-codel name=Fq_Codel_Small_Down add fq-codel-flows=512 fq-codel-interval=50ms fq-codel-limit=2048 fq-codel-memlimit=64.0MiB fq-codel-quantum=1400 kind=fq-codel name=Fq_Codel_Web_Up add fq-codel-interval=50ms fq-codel-limit=4096 fq-codel-memlimit=128.0MiB fq-codel-quantum=1500 kind=fq-codel name=Fq_Codel_Web_Down add fq-codel-limit=8192 fq-codel-memlimit=128.0MiB fq-codel-quantum=1400 fq-codel-target=8ms kind=fq-codel name=Fq_Codel_Pt_Up add fq-codel-flows=2048 fq-codel-limit=8192 fq-codel-memlimit=256.0MiB fq-codel-quantum=1500 fq-codel-target=8ms kind=fq-codel name=Fq_Codel_Pt_Down add fq-codel-flows=2048 fq-codel-limit=8192 fq-codel-memlimit=128.0MiB fq-codel-quantum=1400 fq-codel-target=20ms kind=fq-codel name=Fq_Codel_Nomark_Up add fq-codel-flows=4096 fq-codel-limit=8192 fq-codel-memlimit=256.0MiB fq-codel-quantum=1500 fq-codel-target=15ms kind=fq-codel name=Fq_Codel_Nomark_Down add fq-codel-flows=2048 fq-codel-limit=8192 fq-codel-memlimit=128.0MiB fq-codel-quantum=1500 kind=fq-codel name=Fq_Codel_Down add fq-codel-flows=2048 fq-codel-interval=50ms fq-codel-limit=4096 fq-codel-memlimit=64.0MiB fq-codel-quantum=1480 kind=fq-codel name=Fq_Codel_Up
|

1 2 3 4
| /ip firewall mangle add action=mark-packet chain=prerouting comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ip firewall mangle add action=mark-packet chain=prerouting comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp /ip firewall mangle add action=mark-packet chain=forward comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ip firewall mangle add action=mark-packet chain=forward comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp
|
1 2 3 4
| /ip firewall mangle add action=mark-packet chain=prerouting comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ip firewall mangle add action=mark-packet chain=prerouting comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp /ip firewall mangle add action=mark-packet chain=forward comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ip firewall mangle add action=mark-packet chain=forward comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp
|
1 2
| /ip firewall mangle add action=mark-packet chain=prerouting comment=SMALL connection-bytes=0-256000 disabled=yes new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 passthrough=no /ip firewall mangle add action=mark-packet chain=forward comment=SMALL connection-bytes=0-256000 disabled=yes new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 passthrough=no
|
- 通过mac地址或IP地址标记qb的流量,可同时标记2个qb,其上传及下载速度将加总后做限制
1 2 3 4 5 6
| /ip firewall mangle add action=mark-connection chain=prerouting comment=qB-1 new-connection-mark=PT-conection src-address=10.0.0.55 /ip firewall mangle add action=mark-connection chain=prerouting comment=qB-2 new-connection-mark=PT-conection src-mac-address=02:42:0A:00:00:1F /ip firewall mangle add action=mark-packet chain=prerouting comment=PT connection-mark=PT-conection new-packet-mark=qBittorent_packet passthrough=no /ip firewall mangle add action=mark-connection chain=forward comment=qB-1 disabled=yes new-connection-mark=PT-conection src-address=10.0.0.55 /ip firewall mangle add action=mark-connection chain=forward comment=qB-2 disabled=yes new-connection-mark=PT-conection src-mac-address=02:42:0A:00:00:1F /ip firewall mangle add action=mark-packet chain=forward comment=PT connection-mark=PT-conection disabled=yes new-packet-mark=qBittorent_packet passthrough=no
|
- 建议根据截图重新排序

- 在ipv6中做相同的mangle,注意mark标记选择与v4时配置的一致
- 通过端口标记DNS流量
1 2 3 4
| /ipv6 firewall mangle add action=mark-packet chain=prerouting comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=prerouting comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp /ipv6 firewall mangle add action=mark-packet chain=forward comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=forward comment=DNS disabled=yes new-packet-mark=Dns-packet passthrough=no port=53,853 protocol=tcp
|
1 2 3 4
| /ipv6 firewall mangle add action=mark-packet chain=prerouting comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ipv6 firewall mangle add action=mark-packet chain=prerouting comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp /ipv6 firewall mangle add action=mark-packet chain=forward comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=tcp /ipv6 firewall mangle add action=mark-packet chain=forward comment=WEB disabled=yes new-packet-mark=Web-packet packet-mark=no-mark passthrough=no port=80,443,8080 protocol=udp
|
1 2
| /ipv6 firewall mangle add action=mark-packet chain=prerouting comment=SMALL connection-bytes=0-256000 disabled=yes new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 passthrough=no /ipv6 firewall mangle add action=mark-packet chain=forward comment=SMALL connection-bytes=0-256000 disabled=yes new-packet-mark=Small-packet packet-mark=no-mark packet-size=0-512 passthrough=no
|
- 通过mac地址或IP地址标记qb的流量,可同时标记2个qb,其上传及下载速度将加总后做限制量
1 2 3 4 5 6
| /ipv6 firewall mangle add action=mark-connection chain=prerouting comment=qB-1 new-connection-mark=PT-conection src-address=dc00::1056 /ipv6 firewall mangle add action=mark-connection chain=prerouting comment=qB-2 new-connection-mark=PT-conection src-mac-address=02:42:0A:00:00:1F /ipv6 firewall mangle add action=mark-packet chain=prerouting comment=PT connection-mark=PT-conection new-packet-mark=qBittorent_packet passthrough=no /ipv6 firewall mangle add action=mark-connection chain=forward comment=qB-1 disabled=yes new-connection-mark=PT-conection src-address=dc00::1055 /ipv6 firewall mangle add action=mark-connection chain=forward comment=qB-2 disabled=yes new-connection-mark=PT-conection src-mac-address=02:42:0A:00:00:1F /ipv6 firewall mangle add action=mark-packet chain=forward comment=PT connection-mark=PT-conection disabled=yes new-packet-mark=qBittorent_packet passthrough=no
|
- 建议根据截图重新排序

- 在queue tree配置流量优先级。分别对up上行和down下行流量进行流控。上下行总带宽及各应用的优先级、允许的最大上下行,Burst Limit突发速率等需根据使用人具体情况逐步调试至最佳状况。
- 本例中,UP中的50M为宽带上传总上限,DOWN中400M为宽带下载总上限,其余各类型流量限速可自行调整
- DNS流量优先级为1(最高),其次为小包流量优先级为2,WEB流量优先级为3,未被标记的兜底流量优先级为6,qBittorrent流量优先级为最低的7
1 2 3 4 5 6 7 8 9 10 11 12 13
| /queue tree add bucket-size=0.05 max-limit=50M name=UP parent=wan queue=Fq_Codel_Up add bucket-size=0.005 max-limit=5M name=1_Dns_up packet-mark=Dns-packet parent=UP priority=1 queue=Fq_Codel_Dns_Up add bucket-size=0.01 max-limit=10M name=2_Small_up packet-mark=Small-packet parent=UP priority=2 queue=Fq_Codel_Small_Up add bucket-size=0.03 burst-limit=60M burst-threshold=10M burst-time=5s max-limit=55M name=3_Web_up packet-mark=Web-packet parent=UP priority=3 queue=Fq_Codel_Web_Up add burst-time=20s max-limit=55M name=6_Nomark_up packet-mark=no-mark parent=UP priority=6 queue=Fq_Codel_Nomark_Up add bucket-size=0.06 max-limit=50M name=7_qb_up packet-mark=qBittorent_packet parent=UP priority=7 queue=Fq_Codel_Pt_Up add bucket-size=0.05 max-limit=400M name=DOWN parent=lan queue=Fq_Codel_Down add bucket-size=0.005 limit-at=5M max-limit=5M name=1_Dns_down packet-mark=Dns-packet parent=DOWN priority=1 queue=Fq_Codel_Dns_Down add bucket-size=0.01 limit-at=10M max-limit=10M name=2_Small_down packet-mark=Small-packet parent=DOWN priority=2 queue=Fq_Codel_Small_Down add bucket-size=0.03 max-limit=400M name=3_Web_down packet-mark=Web-packet parent=DOWN priority=3 queue=Fq_Codel_Web_Down add max-limit=400M name=6_Nomark_down packet-mark=no-mark parent=DOWN priority=6 queue=Fq_Codel_Nomark_Down add bucket-size=0.06 max-limit=400M name=7_qb_down packet-mark=qBittorent_packet parent=DOWN priority=7 queue=Fq_Codel_Pt_Down
|
