RouteOS(MikroTik)流控策略:HTB和PCQ
4 人贊了文章
哈哈,好久沒有寫文章了
做了這麼久的網路,現感覺網路中的流控至關重要,無論在什麼網路中,都需要保證網路業務的正常開展,重要的業務絕不能有高延時,比如:遊戲。反而看起來一些不重要的業務,可以有較高的延時,比如說:下載,視頻
相信大家聽說RouteOS(MikroTik)的HTB和PCQ結合起來一起使用吧。
網路上奇奇怪怪的教程多的很,也都是一些老舊教程,不適用現在高速的網路環境。
也只是一些零星的設置,不能完整的介紹一個綜合程度較高的網路流控解決方案
下面開始正常介紹和綜合網路中零星的知識,還要自己根據心得體會,重新寫出來的HTB和PCQ
廢話不多說,正式開始:
第一:RouteOS路由器重要的標記(Mangle)
針對大小包進行標記標記代碼:
/ip firewall mangleadd action=mark-connection chain=prerouting new-connection-mark=Conn passthrough=yes src-address=192.168.112.2-192.168.112.254add action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-tcp-smaller packet-size=0-256 passthrough=yes protocol=tcpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-tcp-small packet-size=257-512 passthrough=yes protocol=tcpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-tcp-normal packet-size=513-1024 passthrough=yes protocol=tcpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-tcp-big packet-size=1025-65535 passthrough=yes protocol=tcpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-udp-smaller packet-size=0-256 passthrough=yes protocol=udpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-udp-small packet-size=257-512 passthrough=yes protocol=udpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-udp-normal packet-size=513-1024 passthrough=yes protocol=udpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-udp-big packet-size=1025-65535 passthrough=yes protocol=udpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-icmp passthrough=yes protocol=icmpadd action=mark-packet chain=forward connection-mark=Conn disabled=yes dst-port=80 new-packet-mark=pack-upload-web passthrough=yes protocol=tcpadd action=mark-packet chain=forward connection-mark=Conn disabled=yes new-packet-mark=pack-download-web passthrough=yes protocol=tcp src-port=80add action=mark-packet chain=forward connection-mark=Conn disabled=yes dst-port=443 new-packet-mark=pack-upload-web passthrough=yes protocol=tcpadd action=mark-packet chain=forward connection-mark=Conn disabled=yes new-packet-mark=pack-download-web passthrough=yes protocol=tcp src-port=443add action=mark-packet chain=forward connection-mark=Conn dst-port=53 new-packet-mark=pack-upload-dns passthrough=yes protocol=udpadd action=mark-packet chain=forward connection-mark=Conn new-packet-mark=pack-download-dns passthrough=yes protocol=udp src-port=53add action=mark-packet chain=forward connection-mark=Conn content=weixin.qq.com new-packet-mark=pack-important passthrough=yes
此代碼片段重在標記網路中的大小包。
第二,RouteOS路由器流控設置中Queue Tree:
/queue treeadd max-limit=100M name=queue-download parent=bridge1 queue=pcq-download-defaultadd max-limit=10M name=queue-upload parent=pppoe-out1 queue=pcq-upload-defaultadd name=queue-download-icmp packet-mark=pack-icmp parent=queue-download priority=2 queue=pcq-download-defaultadd name=queue-download-tcp parent=queue-download queue=pcq-download-defaultadd name=queue-download-udp parent=queue-download priority=7 queue=pcq-download-defaultadd name=queue-download-tcp-small packet-mark=pack-tcp-small parent=queue-download-tcp priority=4 queue=pcq-download-defaultadd name=queue-download-tcp-normal packet-mark=pack-tcp-normal parent=queue-download-tcp priority=6 queue=pcq-download-defaultadd name=queue-download-tcp-big packet-mark=pack-tcp-big parent=queue-download-tcp queue=pcq-download-defaultadd name=queue-download-udp-small packet-mark=pack-udp-small parent=queue-download-udp priority=3 queue=pcq-download-defaultadd name=queue-download-udp-normal packet-mark=pack-udp-normal parent=queue-download-udp priority=5 queue=pcq-upload-defaultadd name=queue-download-udp-big packet-mark=pack-udp-big parent=queue-download-udp priority=7 queue=pcq-download-defaultadd name=queue-upload-icmp packet-mark=pack-icmp parent=queue-upload priority=2 queue=pcq-upload-defaultadd name=queue-upload-tcp parent=queue-upload queue=pcq-upload-defaultadd name=queue-upload-udp parent=queue-upload priority=7 queue=pcq-upload-defaultadd name=queue-upload-tcp-small packet-mark=pack-tcp-small parent=queue-upload-tcp priority=4 queue=pcq-upload-defaultadd name=queue-upload-tcp-normal packet-mark=pack-tcp-normal parent=queue-upload-tcp priority=6 queue=pcq-upload-defaultadd name=queue-upload-tcp-big packet-mark=pack-tcp-big parent=queue-upload-tcp queue=pcq-upload-defaultadd name=queue-upload-udp-small packet-mark=pack-udp-small parent=queue-upload-udp priority=3 queue=pcq-upload-defaultadd name=queue-upload-udp-normal packet-mark=pack-udp-normal parent=queue-upload-udp priority=5 queue=pcq-upload-defaultadd name=queue-upload-udp-big packet-mark=pack-udp-big parent=queue-upload-udp priority=7 queue=pcq-upload-defaultadd name=queue-download-important packet-mark=pack-important parent=queue-download priority=1 queue=pcq-download-defaultadd name=queue-upload-important packet-mark=pack-important parent=queue-upload priority=1 queue=pcq-upload-defaultadd name=queue-download-dns packet-mark=pack-download-dns parent=queue-download priority=1 queue=pcq-download-defaultadd name=queue-upload-dns packet-mark=pack-upload-dns parent=queue-upload priority=1 queue=pcq-upload-defaultadd name=queue-download-tcp-smaller packet-mark=pack-tcp-smaller parent=queue-download-tcp priority=2 queue=pcq-download-defaultadd name=queue-download-udp-smaller packet-mark=pack-udp-smaller parent=queue-download-udp priority=1 queue=pcq-download-defaultadd name=queue-upload-tcp-smaller packet-mark=pack-tcp-smaller parent=queue-upload-tcp priority=2 queue=pcq-upload-defaultadd name=queue-upload-udp-smaller packet-mark=pack-udp-smaller parent=queue-upload-udp priority=1 queue=pcq-upload-default
建立隊列樹的時候,需要選擇隊列類型,此時需要選擇PCQ
這裡要著重減少PCQ隊列類型,相信官方的文檔還是比較靠譜的。
介紹我的編寫的腳本動態調節PCQ的Rate,限速,這裡我經過實際觀察,發現版本的不一致限速Rate還是差距較大的。
第三,動態調節PCQ的Rate限速。
{:local s [:len [/ip arp find where interface="bridge1"]];:local down [/queue type get value-name=pcq-rate [/queue type find where name="pcq-download-default"] ];:local up [/queue type get value-name=pcq-rate [/queue type find where name="pcq-upload-default"] ];:if ( $s <= 20) do={:local newdown (100000000 - ($s*4000000));:if ( $down != $newdown) do={ /queue type set pcq-rate=$newdown [/queue type find where name="pcq-download-default"];:log warning "已改變PCQ下載限速";}:local newup (10000000 - ($s*400000));:if ( $up != $newup) do={/queue type set pcq-rate=$newup [/queue type find where name="pcq-upload-default"];:log warning "已改變PCQ上傳限速";}}:if ( $s > 20 && $s <= 30) do={:local newdown (20000000 - (($s-20)*800000)); :local newup (2000000 - (($s-20)*80000));:if ( $down != $newdown) do={/queue type set pcq-rate=$newdown [/queue type find where name="pcq-download-default"];:log warning "已改變PCQ下載限速";}:if ( $up != $newup) do={/queue type set pcq-rate=$newup [/queue type find where name="pcq-upload-default"];:log warning "已改變PCQ上傳限速";}}:if ( $s > 30) do={:if ( $down != 8000000 ) do={/queue type set pcq-rate=8000000 [/queue type find where name="pcq-download-default"];:log warning "已改變PCQ下載限速";}:if ( $up != 800000) do={/queue type set pcq-rate=800000 [/queue type find where name="pcq-upload-default"];:log warning "已改變PCQ上傳限速";}}}
此腳本根據ip-arp的在線mac地址動態調節PCQ的Rate限速。
至此,完成了RouteOS對流控策略HTB(大小包)和PCQ(動態調節Rate的限制)
歡迎大家使用該代碼及腳本為自己負責的網路提供更好的網路質量。
本代碼及腳本經過本人半年測試,使用良好,但是也要根據網路做出修改。
如有錯誤,歡迎斧正。
本人已經失業了,有沒有人介紹過工作?
不介紹工作,來瀏覽本座的網站http://www.nearbyshare.com
推薦閱讀:
※計算機網路---題目(持續更新)
※公司內網搭建代理DNS使用內網域名代替ip地址
※LBS基站定位如何營救來自手機的「致命呼救」
※各種加密代理協議的簡單對比
※網路喚醒原理淺析(Wake On LAN)