Pages

Thursday, 24 April 2014

Mikrotik speed it up

This is an attempt to speed up the connection of Mikrotik in the local network to services and others.

First let us begin with the TOS. As far as I understood from the Winbox interface - it is the same as DSC on further looking into it seems a bit different. Anyways here is what I have for ToS and what the numbers behind it actually mean:

new-tos (max-reliability | max-throughput | min-cost | min-delay | normal integer) - specify TOS value to be used in conjunction with action=change-tos
max-reliability - maximize reliability (ToS=4)
max-throughput - maximize throughput (ToS=8)
min-cost - minimize monetary cost (ToS=2)
min-delay - minimize delay (ToS=16)
normal - normal service (ToS=0) 

You will probably ask yourself why DSC of 5,6,7 here please see the script in the references below - it's a way of prioritizing the traffic in your network so it is normal to have different but close values.

From here you will find a print out of my configuration in
/ip firewall mangle


Here it is very confusing when you have the connection marks (CM) and packet marks (PM) - just don't confuse those, since they mean different things especially if you do this from the WinBox  interface - mistakes can happen, but it is easier to understand the rules if you do it from WinBox. Also one note if you try to configure this from command line you should make the command be 1 line meaning that the text should not have a new line (Enter) it will break the command and this is a common mistake. 

/ip firewall mangle add

 chain=prerouting action=mark-connection new-connection-mark=ICMP-CM passthrough=yes protocol=icmp src-address=192.168.1.0/24 

chain=prerouting action=mark-packet new-packet-mark=ICMP-PM passthrough=yes connection-mark=ICMP-CM 

 chain=prerouting action=change-dscp new-dscp=6 passthrough=yes packet-mark=ICMP-PM 

chain=prerouting action=mark-connection new-connection-mark=DNS-CM passthrough=yes protocol=tcp src-address=192.168.1.0/24 dst-port=53 

chain=prerouting action=mark-connection new-connection-mark=DNS-CM passthrough=yes protocol=udp src-address=192.168.1.0/24 dst-port=53,5353 

chain=prerouting action=mark-packet new-packet-mark=DNS-PM passthrough=yes connection-mark=DNS-CM 

 chain=prerouting action=change-dscp new-dscp=6 passthrough=yes packet-mark=DNS-PM 

Winbox Port 8291 (Local Management)
     chain=input action=change-dscp new-dscp=7 passthrough=yes protocol=tcp dst-port=8291 

Skype, HTTPS
     chain=postrouting action=change-dscp new-dscp=7 passthrough=yes protocol=tcp dst-port=443 

Priority - 6 - SSH
     chain=prerouting action=set-priority new-priority=6 passthrough=yes protocol=udp port=22 

Priority - 5 - HTTP Requests
     chain=prerouting action=set-priority new-priority=5 passthrough=yes protocol=tcp dst-port=80 connection-bytes=0-5000000 

Priority - 5 - Yahoo IM
     chain=prerouting action=set-priority new-priority=5 passthrough=yes protocol=tcp port=5050 

Priority - 0 - VOIP - skypetoskype
     chain=forward action=set-priority new-priority=7 passthrough=yes layer7-protocol=skypetoskype  

/queue type add name=PFIFO-64 kind=pfifo pfifo-limit=64
/queue tree add name=ICMP parent=ether1-gateway packet-mark=ICMP-PM priority=1 limit-at=8000 max-limit=16000 queue=PFIFO-64
/queue tree add name=DNS parent=ether1-gateway packet-mark=DNS-PM priority=1 limit-at=8000 max-limit=16000 queue=PFIFO-64

Some Layer-7 Priorities:

/ip firewall layer7-protocol

add action=set-priority chain=forward comment="Priority - 0 - File Sharing - Bittorrent" layer7-protocol=bittorrent
add name=bittorrent regexp="^(\13bittorrent protocol|azver\01\$|get /scrape\\\
    \?info_hash=)|d1:ad2:id20:|\08'7P\\)[RP]"

add name=skypeout regexp="^(\01.\?.\?.\?.\?.\?.\?.\?.\?\01|\02.\?.\?.\?.\?.\?.\
    \?.\?.\?\02|\03.\?.\?.\?.\?.\?.\?.\?.\?\03|\04.\?.\?.\?.\?.\?.\?.\?.\?\04|\
    \05.\?.\?.\?.\?.\?.\?.\?.\?\05|\06.\?.\?.\?.\?.\?.\?.\?.\?\06|\07.\?.\?.\?\
    .\?.\?.\?.\?.\?\07|\08.\?.\?.\?.\?.\?.\?.\?.\?\08|\t.\?.\?.\?.\?.\?.\?.\?.\
    \?\t|\
    \n.\?.\?.\?.\?.\?.\?.\?.\?\
    \n|\0B.\?.\?.\?.\?.\?.\?.\?.\?\0B|\0C.\?.\?.\?.\?.\?.\?.\?.\?\0C|\r.\?.\?.\
    \?.\?.\?.\?.\?.\?\r|\0E.\?.\?.\?.\?.\?.\?.\?.\?\0E|\0F.\?.\?.\?.\?.\?.\?.\
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A.\?.\?.\?.\?.\?.\?.\?.\?\FA|\FB.\?.\?.\?.\?.\?.\?.\?\
    .\?\FB|\FC.\?.\?.\?.\?.\?.\?.\?.\?\FC|\FD.\?.\?.\?.\?.\?.\?.\?.\?\FD|\FE.\
    \?.\?.\?.\?.\?.\?.\?.\?\FE|\FF.\?.\?.\?.\?.\?.\?.\?.\?\FF)"
add name=skypetoskype regexp="^..\02............."


/ip firewall mangle add action=set-priority chain=forward comment="Priority - 0 - VOIP - skypetoskype" layer7-protocol=skypetoskype new-priority=7