Mikrotik RouterOS: Simple Policy Based Routing

So let’s say you have multiple ISPs or different rules for VLAN traffic and you want a simple way to define which network routes through which gateway.

In this example we have a routing table main and a routing table 4G

  • Routing table main uses the default route which is a PPPoE connection on the same router.
  • Routing table 4G uses a secondary router which has IP Address 172.20.0.29

Defining Routes

First we need to define our default route. This may already exist:

/ip route dst-address=0.0.0.0/0 gateway=PPPoE

Next we need to add a route to the second gateway with a routing mark.

/ip route dst-address=0.0.0.0/0 gateway=172.20.0.29 routing-mark=4G

Once you are finished your Route List in Winbox will look similar to this:

This is self-explanatory, all external traffic will go through the PPPoE interface and all traffic marked 4G will route through 172.20.0.29.

Now we need to define the subnets that will have the routing marks applied.

To achieve this we need to define the traffic that will be marked. For this example we want to mark all traffic from 192.168.200.0/24 to go through gateway 172.20.0.29:

/ip route rule add src-address=192.168.200.0/24 dst-address=0.0.0.0/0 action=lookup table=4G

However now all local traffic from 192.168.200.0/24 will go through the 4G router rather than the main router.

To resolve this you need to add a rule for the local network before the rule above to route local traffic using the router’s main lookup table:

/ip route rule add src-address=192.168.200.0/24 dst-address=172.20.0.0/16 action=lookup table=main

Here is a screenshot of my Router on a Stick configuration that handles VLAN traffic on my LAN.

You can see there are three lookup tables and three subnets with their associated routing rules:

It’s fairly obvious but you can see how rules are processed in order and that subnet 192.168.200.0/24 uses the 4G lookup table and 192.168.101.0/24 subnet uses the UBNT table.

Leave a Reply

Your e-mail address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.