Wireless Connect Logo
Hello Guest! - Login
Contact Wireless Connect
Routes, Equal Cost Multipath Routing, Policy Routing
Credit Cards Accepted
Back to Table Of Contents >>

General Information


The following manual surveys the IP routes management, equal-cost multi-path (ECMP) routing technique, and policy-based routing.


Packages required: system
License required: Level1
Submenu level: /ip route
Standards and Technologies: IP (RFC 791)
Hardware usage: Not significant


MikroTik RouterOS has following types of routes:

  • dynamic routes - automatically created routes for networks, which are directly accessed through an interface. They appear automatically, when adding a new IP address. Dynamic routes are also added by routing protocols.
  • static routes - user-defined routes that specify the router which can forward traffic to the specified destination network. They are useful for specifying the default gateway. The gateway for static routes may be checked (with either ARP or ICMP protocol) for reachability, so that different gateways with different priorities (costs) may be assigned for one destination network to provide failover.

ECMP (Equal Cost Multi-Path) Routing

This routing mechanism enables packet routing along multiple paths with equal cost and ensures load balancing. With ECMP routing, you can use more than one gateway for one destination network (this approach may also be configured to provide failover). With ECMP, a router potentially has several available next hops towards a given destination. A new gateway is chosen for each new source/destination IP pair. It means that, for example, one FTP connection will use only one link, but new connection to a different server will use another link. ECMP routing has another good feature - single connection packets do not get reordered and therefore do not kill TCP performance.

The ECMP routes can be created by routing protocols (RIP or OSPF), or by adding a static route with multiple gateways, separated by a comma (e.g., /ip route add gateway=, The routing protocols may create multipath dynamic routes with equal cost automatically, if the cost of the interfaces is adjusted propery. For more information on using routing protocols, please read the corresponding Manual.

Policy-Based Routing

It is a routing approach where the next hop (gateway) for a packet is chosen, based on a policy, which is configured by the network administrator. In RouterOS the procedure the follwing:

  • mark the desired packets, with a routing-mark
  • choose a gateway for the marked packets

Note! In routing process, the router decides which route it will use to send out the packet. Afterwards, when the packet is masqueraded, its source address is taken from the prefsrc field.


Submenu level: /ip route


In this submenu you can configure Static, Equal Cost Multi-Path and Policy-Based Routing and see the routes.

Property Description

bgp-as-path (text) - manual value of BGP's as-path for outgoing routebgp-atomic-aggregate (yes | no) - indication to receiver that it cannot "deaggregate" the prefixbgp-communities (multiple choice: integer) - administrative policy marker, that can travel through different autonomous systems

internet - communities value 0

bgp-local-pref (integer) - local preference value for a routebgp-med (integer) - a BGP attribute, which provides a mechanism for BGP speakers to convey to an adjacent AS the optimal entry point into the local ASbgp-origin (incomplete | igp | egp) - the origin of the route prefixbgp-prepend (integer: 0..16) - number which indicates how many times to prepend AS_NAME to AS_PATHcheck-gateway (arp | ping; default: ping) - which protocol to use for gateway reachabilitydistance (integer: 0..255) - administrative distance of the route. When forwarding a packet, the router will use the route with the lowest administrative distance and reachable gatewaydst-address (IP address/netmask; default: - destination address and network mask, where netmask is number of bits which indicate network number. Used in static routing to specify the destination which can be reached, using a gateway - any network

gateway (IP address) - gateway host, that can be reached directly through some of the interfaces. You can specify multiple gateways separated by a comma "," for ECMP routespref-src (IP address) - source IP address of packets, leaving router via this route - pref-src is determined automatically

routing-mark (name) - a mark for packets, defined under /ip firewall mangle. Only those packets which have the according routing-mark, will be routed, using this gatewayscope (integer: 0..255) - a value which is used to recursively lookup the nexthop addresses. Nexthop is looked up only through routes that have scope <= target-scope of the nexthoptarget-scope (integer: 0..255) - a value which is used to recursively lookup the next-hop addresses. Each nexthop address selects smallest value of target-scope from all routes that use this nexthop address. Nexthop is looked up only through routes that have scope <= target-scope of the nexthop


You can specify more than one or two gateways in the route. Moreover, you can repeat some routes in the list several times to do a kind of cost setting for gateways.


To add two static routes to networks and (the default destination address) on a router with two interfaces and two IP addresses:

[admin@MikroTik] ip route> add dst-address= gateway=
[admin@MikroTik] ip route> add gateway=
[admin@MikroTik] ip route> print
Flags: X - disabled, A - active, D - dynamic, 
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme, 
B - blackhole, U - unreachable, P - prohibit 
 #      DST-ADDRESS        PREF-SRC        G GATEWAY         DIS INTE...
 0 A S       r            Local
 1 ADC                                   Public
 2 ADC                                Local
 3 A S          r                 Public
[admin@MikroTik] ip route>

Policy Rules

Submenu level: /ip route rule

Property Description

action (drop | unreachable | lookup; default: unreachable) - action to be processed on packets matched by this rule:

drop - silently drop packet
unreachable - reply that destination host is unreachable
lookup - lookup route in given routing table

dst-address (IP address:netmask) - destination IP address/maskinterface (name; default: "") - interface through which the gateway can be reachedrouting-mark (name; default: "") - mark of the packet to be mached by this rule. To add a routing mark, use '/ip firewall mangle' commandssrc-address (IP address:netmask) - source IP address/masktable (name; default: "") - routing table, created by user


You can use policy routing even if you use masquerading on your private networks. The source address will be the same as it is in the local network. In previous versions of RouterOS the source address changed to

It is impossible to recognize peer-to-peer traffic from the first packet. Only already established connections can be matched. That also means that in case source NAT is treating Peer-to-Peer traffic differently from the regular traffic, Peer-to-Peer programs will not work (general application is policy-routing redirecting regular traffic through one interface and Peer-to-Peer traffic - through another). A known workaround for this problem is to solve it from the other side: making not Peer-to-Peer traffic to go through another gateway, but all other useful traffic go through another gateway. In other words, to specify what protocols (HTTP, DNS, POP3, etc.) will go through the gateway A, leaving all the rest (so Peer-to-Peer traffic also) to use the gateway B (it is not important, which gateway is which; it is only important to keep Peer-to-Peer together with all traffic except the specified protocols)


To add the rule specifying that all the packets from the host should lookup the mt routing table:

[admin@MikroTik] ip firewall mangle add action=mark-routing new-routing-mark=mt \
\... chain=prerouting
[admin@MikroTik] ip route> add gateway= routing-mark=mt
[admin@MikroTik] ip route rule> add src-address= \
\... table=mt action=lookup
[admin@MikroTik] ip route rule> print
Flags: X - disabled, I - invalid
 0   src-address= action=lookup table=mt
[admin@MikroTik] ip route rule>

Application Examples

Static Equal Cost Multi-Path routing

Consider the following situation where we have to route packets from the network to 2 gateways - and

mikrotik emcp router

Note that the ISP1 gives us 2Mbps and ISP2 - 4Mbps so we want a traffic ratio 1:2 (1/3 of the source/destination IP pairs from goes through ISP1, and 2/3 through ISP2).

IP addresses of the router:

[admin@ECMP-Router] ip address> print
Flags: X - disabled, I - invalid, D - dynamic
 #   ADDRESS            NETWORK         BROADCAST       INTERFACE
 0   Local
 1       Public1
 2       Public2
[admin@ECMP-Router] ip address>

Add the default routes - one for ISP1 and 2 for ISP2 so we can get the ratio 1:3:

[admin@ECMP-Router] ip route> add gateway=,,
[admin@ECMP-Router] ip route> print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf
 0 ADC                                   Public1
 1 ADC                                   Public2
 2 ADC                                Local
 3 A S          r                 Public1
                          r                 Public2
                          r                 Public2
[admin@ECMP-Router] ip route>

Standard Policy-Based Routing with Failover

This example will show how to route packets, using an administrator defined policy. The policy for this setup is the following: route packets from the network, using gateway, and packets from network, using gateway If GW_1 does not respond to pings, use GW_Backup for network, if GW_2 does not respond to pings, use GW_Backup also for network instead of GW_2.

The setup:

Mikrotik Policy route

Configuration of the IP addresses:

[admin@PB-Router] ip address> print
Flags: X - disabled, I - invalid, D - dynamic
 #   ADDRESS            NETWORK         BROADCAST       INTERFACE
 0   Local1
 1   Local2
 2      Public
[admin@PB-Router] ip address>

To achieve the described result, follow these configuration steps:

  1. Mark packets from network with a new-routing-mark=net1, and packets from network with a new-routing-mark=net2:

    [admin@PB-Router] ip firewall mangle> add src-address= \
    \... action=mark-routing new-routing-mark=net1 chain=prerouting
    [admin@PB-Router] ip firewall mangle> add src-address= \
    \... action=mark-routing new-routing-mark=net2 chain=prerouting
    [admin@PB-Router] ip firewall mangle> print
    Flags: X - disabled, I - invalid, D - dynamic
     0   chain=prerouting src-address= action=mark-routing
     1   chain=prerouting src-address= action=mark-routing
    [admin@PB-Router] ip firewall mangle>
  2. Route packets from network to gateway GW_1 (, packets from network to gateway GW_2 (, using the according packet marks. If GW_1 or GW_2 fails (does not reply to pings), route the respective packets to GW_Main (

    [admin@PB-Router] ip route> add gateway= routing-mark=net1 \
    \... check-gateway=ping
    [admin@PB-Router] ip route> add gateway= routing-mark=net2 \
    \... check-gateway=ping
    [admin@PB-Router] ip route> add gateway=
    [admin@PB-Router] ip route> print
    Flags: X - disabled, A - active, D - dynamic,
    C - connect, S - static, r - rip, b - bgp, o - ospf
     0 ADC                                   Public
     1 ADC                                Local1
     2 ADC                                Local2
     3 A S                          r                 Public
     4 A S                          r                 Public
     5 A S                          r                 Public
    [admin@PB-Router] ip route>
Back to Table Of Contents >>