How To Mikrotik Youtube Routing To Other Wan (Interface)

route youtube mikrotik
In this tutorial we route youtube.com to other dedicated wan link.
We need to classify the traffic through ROUTE MARKING.
There are following 4 simple steps

Step # 1 “Script”

Lot of people want to do something with connections to Google and YouTube, but they change IP addresses so often and make problems to track. One of the solutions is to dinamically update address lists on your Mikrotik router.

This script create Prefect youtube address-list

Mikrotik Script

:foreach i in=[/ip dns cache find] do={
    :local bNew "true";
    :local cacheName [/ip dns cache all get $i name] ;
#    :put $cacheName;

    :if ([:find $cacheName "youtube"] != 0) do={

        :local tmpAddress [/ip dns cache get $i address] ;
#	:put $tmpAddress;

# if address list is empty do not check
        :if ( [/ip firewall address-list find ] = "") do={
            :log info ("added entry: $[/ip dns cache get $i name] IP $tmpAddress");
            /ip firewall address-list add address=$tmpAddress list=youtube_dns_ips comment=$cacheName;
        } else={
            :foreach j in=[/ip firewall address-list find ] do={
                :if ( [/ip firewall address-list get $j address] = $tmpAddress ) do={
                    :set bNew "false";
                }
            }
            :if ( $bNew = "true" ) do={
                :log info ("added entry: $[/ip dns cache get $i name] IP $tmpAddress");
                /ip firewall address-list add address=$tmpAddress list=youtube_dns_ips comment=$cacheName;
            }
        }
    }
}

Step # 2 “Scheduler”
Create a Schedule to update the address-list

Mikrotik Scheduler

/system scheduler add name=youtube start-time=startup interval=0
0:00:20 on-event="/system script run youtube-script"

Mikrotik address list

Step # 3 “Firewall Mangle”
Now we mark route for youtube

Mikrotik Firewall

/ip firewall mangle add chain=prerouting protocol=tcp dst-port=80 
dst-address-list=youtube_dns_ips action=mark-routing 
new-routing-mark=youtube_route passthrough=yes

Step # 4 “Route”
Now Add Route For youtube.

Mikrotik route

/ip route add comment=”Youtube Route Traffic admsln.team@gmail.com" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=197.1.1.2 routing-mark=youtube_route scope=255 target-scope=10

Mikrotik Day Night Queue Limit Change

/queue simple
name=”Day” target-addresses=197.1.1.0/24 dst-address=0.0.0.0/0
interface=ether2 parent=none direction=both priority=8
queue=default-small/default-small limit-at=256k/256k
max-limit=256k/256k total-queue=default-small

name=”Night” target-addresses=197.1.1.0/24 dst-address=0.0.0.0/0
interface=ether2 parent=none direction=both priority=8
queue=default-small/default-small limit-at=512k/512k
max-limit=512k/512k total-queue=default-small

/system scheduler
#name=”Day” on-event=Day policy=read,write start-date=jun/11/2011 start-time=17:45:29 interval=1d

#name=”Night” on-event=Night policy=read,write start-date=jun/11/2011 start-time=17:50:29 interval=1d

Mikrotik Howto give PiNG / iCMP high Priority

If you want to provide PING / ICMP high priority so you wont get any high delay in ping reply Use the following Code.

 

/ip firewall mangle
add chain=prerouting protocol=icmp action=mark-connection new-connection-mark=icmp-con passthrough=yes comment="" disabled=no

add chain=prerouting protocol=icmp connection-mark=icmp-con action=mark-packet new-packet-mark=icmp-pkt passthrough=no comment="" disabled=no

/queue tree
add burst-limit=0 burst-threshold=0 burst-time=0s disabled=no limit-at=1024k max-limit=2048k name=Hi-Prio-to-icmp-aacable packet-mark=icmp-pkt parent=global-in priority=1 queue=default