Community discussions

MikroTik App
 
mrravirajput
just joined
Topic Author
Posts: 10
Joined: Wed Jul 23, 2014 1:06 pm
Location: New Delhi

Policy Based Routing for YOUTUBE

Sat Aug 20, 2016 10:12 am

Hi,
We are running a small network with two ISPs as primary and secondary. The secondary one remains idle most of the time.
We wish to route only the youtube traffic on the second one. For this mangle rule was created and an address list of you tube is formed.
However, I am not able to figure out on how to forcibly route the traffic for the address list on ISP2.
Please suggest.

Thanks
twin.jpg
You do not have the required permissions to view the files attached to this post.
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Policy Based Routing for YOUTUBE

Tue Aug 23, 2016 12:53 am

The easiest thing to do would be to just use static routes to point YouTube addresses via ISP2.
 
Altare
just joined
Posts: 10
Joined: Wed Jun 22, 2016 1:11 pm

Re: Policy Based Routing for YOUTUBE

Tue Aug 23, 2016 3:05 pm

You only need a policy based route if you wanted only a subset of your LAN devices to use the second circuit, otherwise just use static routes for youtube.
 
User avatar
Cha0s
Forum Guru
Forum Guru
Posts: 1162
Joined: Tue Oct 11, 2005 4:53 pm

Re: Policy Based Routing for YOUTUBE

Tue Aug 23, 2016 4:59 pm

You could try 'catching' youtube traffic using domains in an address list.

First you add youtube domains on an address-list.
You'd have to find out all domains used by youtube using your browser's developer tools.
/ip firewall address-list add list=youtube address=youtube.com
/ip firewall address-list add list=youtube address=www.youtube.com
/ip firewall address-list add list=youtube address=s.ytimg.com
/ip firewall address-list add list=youtube address=i.ytimg.com
/ip firewall address-list add list=youtube address=youtube-nocookie.com
/ip firewall address-list add list=youtube address=r2---sn-xjpm-4g5e.googlevideo.com
/ip firewall address-list add list=youtube address=r5---sn-hpa7zn7r.googlevideo.com
...
..
.
The googlevideo.com domain is kind of tricky since it changes depending on content. And since it's on https, an L7 rule most likely won't work.
If you use Mikrotik's DNS server, you can write a script that will check the DNS cache for all entries containing googlevideo.com and add the resolved IPs to the youtube address-list.

Then you add a mangle rule to mark-routing on packets destined to those domains (ips).
/ip firewall mangle add dst-address-list=youtube action=mark-routing routing-mark=youtube
Finally you add a static route for that routing mark with gateway your ISP2.
/ip route add dst-address=0.0.0.0/0 gateway=ISP2 routing-mark=youtube
It's definitely not 'bulletproof' but it should get you started.
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Policy Based Routing for YOUTUBE

Tue Aug 23, 2016 5:08 pm

OP did say that he has an address list for YouTube as his basis for the policy routing.

Since the stated goal is a destination-based policy, I recommend using routes (which are destination-centric by their very nature) instead of packet marking.
- it's much easier to understand
- it's much more efficient in the router

Although the ability to leverage the dns-based address list feature certainly has advantages
- it's more flexible - it moves dynamically with DNS
- You could use the "youtube" connection marks for other things like QoS
 
User avatar
Cha0s
Forum Guru
Forum Guru
Posts: 1162
Joined: Tue Oct 11, 2005 4:53 pm

Re: Policy Based Routing for YOUTUBE

Tue Aug 23, 2016 5:12 pm

Yes you are right, and if the website in question was something simple (eg: forum.mikrotik.com) I would agree with the 'static routes' approach.

But youtube is chaotic. You can't realistically find all IPs of this HUGE geo-distributed service and keep them up to date.

I think my approach is more realistic for the task at hand.
 
User avatar
ZeroByte
Forum Guru
Forum Guru
Posts: 4047
Joined: Wed May 11, 2011 6:08 pm

Re: Policy Based Routing for YOUTUBE

Tue Aug 23, 2016 5:18 pm

Me, I'd just look up Google's IP blocks and route those. Who cares if Google Docs and GMail go the same way too? This is just a traffic engineering exercise and if a little extra Googleness comes in on ISP2 along with the videos, so be it. Google's IPv4 blocks are going to be fairly stable, given that the RIRs don't have any more addresses to hand out to organizations, and certainly not in the block sizes that Google consumes.