Policy routing implementation example
Basically when you implement routing you have set of routes (static or dynamic) that tell the router how to reach certain destination. Policy routing does the same task, but may be different routes for various types of traffic. All routes by default are installed into main routing table which content can be displayed with following command:
[admin@MikroTik] /ip route> print where routing-mark=main
All routes with
appropriate routing-mark are shown using command:
[admin@MikroTik] /ip route> print
or
[admin@MikroTik] /ip route> print where routing-mark=all
In this case routing-mark denote appropriate routing table.
When we implement the policy routing there can be used others routing tables that includes routes for specific traffic or destination network. In this example, are explored the requirements for setting up policy routing and is given simple implementation example.
Implementation of policy routing consists of 3 steps:
- The first step is to define the routes and which policies (routing table) will use those routes.
- The second step to define the routing rules, which will define how the policies apply to certain traffic.
- The third is to define the actual policies. We’ll look at each of these individually.
The network below is the one we will use for this example.
Task of this example is to create routing policy that route all traffic from LAN 192.168.1.0/24 over provider “ISP-A” and all traffic from 192.168.2.0/24 via provider ISP-B.
Set up routing policy using ip route rule
I assume that IP addresses already have set up on your router. We will add three “default” routes for each of routing table. These are below:
/ip route add dst-address=0.0.0.0/0
gateway=11.1.1.1 routing-mark=Table_A
/ip route add dst-address=0.0.0.0/0
gateway=12.1.1.1 routing-mark=Table_B
/ip route add dst-address=0.0.0.0/0
gateway=11.1.1.1
The first two routes will be used by our policies, one for routing table Table_A and one for Table_B. The third route will be used by any traffic does not have a policy defined and by traffic from the router itself (it refered to main routing table), to define routing-mark=main is not mandatory because it is by default.
Next, we need to define our routing rules (policy). There are several ways to accomplish this, and one of simplest way is given below.
/ip route rule>add src-address=192.168.1.0/24 action=lookup
table=Table_A
/ip route rule>add src-address=192.168.2.0/24 action=lookup
table=Table_B
Note: If routes
entries in specific routing table doesn’t satisfy particular traffic router
looks for next hop (gateway) in the main routing table.
Reference: https://wiki.mikrotik.com/wiki/Testwiki/IP_routing