MikroTik QoS 配置指南 - 流量优先级限速优化方案
方案概述
通过流量标记和队列管理实现以下优先级:
- 最高优先级:PING、DNS
- 次优先级:小包流量(上行<192B/下行<512B)、网页流量
- 最低优先级:其他常规流量
一、流量标记配置(Mangle)
1.1 整体配置视图
1.2 配置脚本
/ip firewall mangle
# ICMP标记
add action=mark-packet chain=forward comment="Mark Ping" new-packet-mark=PING passthrough=no protocol=icmp
# DNS标记
add action=mark-packet chain=forward comment="Mark DNS Query" new-packet-mark=DNS_P passthrough=no port=53 protocol=udp
# SpeedTest标记
add action=mark-packet chain=forward comment="Mark SpeedTest" new-packet-mark=SpeedTest passthrough=no port=8080 protocol=tcp
# Web流量标记(HTTP/HTTPS)
add action=mark-connection chain=forward comment="Mark Web Traffic" new-connection-mark=WebC passthrough=yes port=80,443 protocol=tcp
add action=mark-connection chain=forward new-connection-mark=WebC passthrough=yes port=80,443 protocol=udp
add action=mark-packet chain=forward connection-mark=WebC new-packet-mark=WebP passthrough=no
# 小包流量标记
add action=mark-connection chain=forward comment="Mark MiniPackets Down" dst-address=192.168.0.0/16 new-connection-mark=MiniCDown packet-size=0-512 passthrough=yes
add action=mark-packet chain=forward connection-mark=MiniCDown dst-address=192.168.0.0/16 new-packet-mark=MiniPDown passthrough=no
add action=mark-connection chain=forward comment="Mark MiniPackets Up" new-connection-mark=MiniCUp packet-size=0-192 passthrough=yes src-address=192.168.0.0/16
add action=mark-packet chain=forward connection-mark=MiniCUp new-packet-mark=MiniPUp passthrough=no src-address=192.168.0.0/16
# 常规流量标记
add action=mark-connection chain=forward comment="Mark General Down" dst-address=192.168.0.0/16 new-connection-mark=GenDownC passthrough=yes
add action=mark-packet chain=forward connection-mark=GenDownC dst-address=192.168.0.0/16 new-packet-mark=GenDownP passthrough=no
add action=mark-connection chain=forward comment="Mark General Up" new-connection-mark=GenUpC passthrough=yes src-address=192.168.0.0/16
add action=mark-packet chain=forward connection-mark=GenUpC new-packet-mark=GenUpP passthrough=no src-address=192.168.0.0/16
1.3 Web流量标记示例
二、队列类型配置
2.1 队列类型视图
2.2 Web流量队列示例
2.3 配置脚本
/queue type
add kind=pcq name=Gen_Down pcq-classifier=src-address pcq-rate=12M pcq-total-limit=20000KiB
add kind=pcq name=Gen_UP pcq-burst-time=20s pcq-classifier=src-address pcq-rate=20M pcq-total-limit=10000KiB
add kind=pcq name=Web pcq-burst-rate=20M pcq-burst-threshold=8M pcq-classifier=src-address pcq-rate=12M pcq-total-limit=10000KiB
三、队列树配置
3.1 队列树结构
3.2 Web限速配置
3.3 配置脚本
/queue tree
add name=A parent=global
add name=DNS packet-mark=DNS_P parent=A priority=1
add name=PingFirst packet-mark=PING parent=A priority=1
add name=B parent=global
add name=MiniPDownFirst packet-mark=MiniPDown parent=B priority=2
add name=MiniPUpFirst packet-mark=MiniPUp parent=B priority=2
add name=SpeedTest packet-mark=SpeedTest parent=B priority=3
add name=Web packet-mark=WebP parent=B priority=4 queue=Web
add name=C parent=global
add name=GenDown packet-mark=GenDownP parent=C queue=Gen_Down
add name=GenUp packet-mark=GenUpP parent=C queue=Gen_UP
四、快速部署脚本
- 下载配置文件
https://cloud.189.cn/web/share?code=7BVNVnjea2Q3(访问码:5ft8) 上传到路由器后执行:
import file=qos.rsc
验证配置:
- 检查队列树匹配计数
- 根据实际带宽调整限速参数
- 内网地址段按需修改(默认192.168.0.0/16)
注意:所有带宽数值需根据实际网络环境调整,建议导入后通过图形界面微调参数。