简介
EdgeRouter 固件 1.8.0 以上版本支持 Advanced-Queue 功能
开启 Advanced-Queue 会影响 offload 效能
工具
EdgeRouter
网络拓扑说明
eth1 : WAN - ISP 提供的静态 IP 地址/网关/ DNS(带宽上传 5M /下载 15M)
eth0 : LAN - 192.168.1.0/24
操作步骤
-
限制整个 LAN 的上传和下载速度
- 在 global 建立一个root queue 1
set traffic-control advanced-queue root queue 1 attach-to global
set traffic-control advanced-queue root queue 1 bandwidth 20mbit- 分别建立 branch 100 上传和 200 下载
set traffic-control advanced-queue branch queue 100 bandwidth 5mbit
set traffic-control advanced-queue branch queue 100 description Upload
set traffic-control advanced-queue branch queue 100 parent 1
set traffic-control advanced-queue branch queue 200 bandwidth 15mbit
set traffic-control advanced-queue branch queue 200 description Download
set traffic-control advanced-queue branch queue 200 parent 1- 在 root queue 1 中建立 filter 分别来应用 branch 100 和 200 配置
set traffic-control advanced-queue filters match 100 attach-to 1
set traffic-control advanced-queue filters match 100 description ‘WAN upload’
set traffic-control advanced-queue filters match 100 ip source address 192.168.1.0/24
set traffic-control advanced-queue filters match 100 target 100
set traffic-control advanced-queue filters match 200 attach-to 1
set traffic-control advanced-queue filters match 200 description ‘WAN download’
set traffic-control advanced-queue filters match 200 ip destination address 192.168.1.0/24
set traffic-control advanced-queue filters match 200 target 200- 建立 FQ_CODEL queue 用于后续 leaf queues 使用
set traffic-control advanced-queue queue-type fq-codel FQCODEL_DOWN
set traffic-control advanced-queue queue-type fq-codel FQCODEL_UP- 分别建立 leaf queue 199 用于默认上传限速和 leaf queue 299 用于默认下载限速,并配置 queue 方式为 FQ_CODEL
set traffic-control advanced-queue leaf queue 199 bandwidth 5mbit
set traffic-control advanced-queue leaf queue 199 description default
set traffic-control advanced-queue leaf queue 199 parent 100
set traffic-control advanced-queue leaf queue 199 queue-type FQCODEL_UP
set traffic-control advanced-queue leaf queue 299 bandwidth 15mbit
set traffic-control advanced-queue leaf queue 299 description default
set traffic-control advanced-queue leaf queue 299 parent 200
set traffic-control advanced-queue leaf queue 299 queue-type FQCODEL_DOWN- 在 branch100 中建立 filter 来应用 leaf 199,在 branch 200 中建立 filter 来应用 leaf 299 配置
set traffic-control advanced-queue filters match 199 attach-to 100
set traffic-control advanced-queue filters match 199 description Default
set traffic-control advanced-queue filters match 199 target 199
set traffic-control advanced-queue filters match 299 attach-to 200
set traffic-control advanced-queue filters match 299 description Default
set traffic-control advanced-queue filters match 299 target 299 -
限制单个 IP 和文件传输应用上传速度
- 建立 leaf queue 201和filter 用于配置IP地址为192.168.1.11的下载速度限制为4M
set traffic-control advanced-queue leaf queue 201 bandwidth 4mbit
set traffic-control advanced-queue leaf queue 201 description 192.168.1.11
set traffic-control advanced-queue leaf queue 201 parent 200
set traffic-control advanced-queue filters match 201 attach-to 200
set traffic-control advanced-queue filters match 201 description ‘limit 192.168.1.11’
set traffic-control advanced-queue filters match 201 ip destination address 192.168.1.11/32
set traffic-control advanced-queue filters match 201 target 201- 建立 leaf queue 101和filter 用于配置文件传输的应用上传速度限制为2M
set traffic-control advanced-queue leaf queue 101 bandwidth 2mbit
set traffic-control advanced-queue leaf queue 101 description file-transfer
set traffic-control advanced-queue leaf queue 101 parent 100
set traffic-control advanced-queue filters match 101 application category File-Transfer
set traffic-control advanced-queue filters match 101 attach-to 100
set traffic-control advanced-queue filters match 101 description ‘limit file-transfer’
set traffic-control advanced-queue filters match 101 target 101- 移除 FQ_CODEL queue,而采用 HFQ queue 来配置 LAN 中每个 IP 的下载速度和上传速度(下载速度 8Mbps,上传速度 3Mbps)
set traffic-control advanced-queue queue-type hfq HFQ_DOWN host-identifier dip
set traffic-control advanced-queue queue-type hfq HFQ_DOWN max-rate 8mbit
set traffic-control advanced-queue queue-type hfq HFQ_DOWN subnet 192.168.1.0/24
set traffic-control advanced-queue leaf queue 299 queue-type HFQ_DOWN
set traffic-control advanced-queue queue-type hfq HFQ_UP host-identifier sip
set traffic-control advanced-queue queue-type hfq HFQ_UP max-rate 3mbit
set traffic-control advanced-queue queue-type hfq HFQ_UP subnet 192.168.1.0/24
set traffic-control advanced-queue leaf queue 199 queue-type HFQ_UP
备注
- 配置某个网段每个 IP 统一限速,只需配置步骤 1 中 (1)-(6) 和步骤 3,HFQ 最多支持 /22 子网掩码。
- 配置 Advanced-Queue 后需要一定时间才能生效,取决于路由器配置文件大小所以生效时间快则几秒慢则几分钟。
- leaf queue 的默认 queue 方式为 PFIFO
- 附件为ER-X-SFP均衡限速192.168.1.0/24的HFQ QOS配置,使用ER-X-SFP的用户可在下载后按需求更改 WAN 连接方式和限速配置(EdgeRouter 默认帐号 ubnt/ubnt)