Routing · Topic 1 of 2

Routing Concepts, the Routing Table and Route Flags

Learn how a MikroTik router picks a route, how to read the routing table and its flags, and what distance, gateway and connected routes mean.

  • 5 min
In a nutshell
  • A router picks the route with the longest prefix match for the destination.
  • If prefixes are equal, the lowest distance wins.
  • A connected route is created automatically when an interface gets an IP address.

What it is

Routing is the process of choosing where to send a packet next, based on its destination IP address.

A router holds a routing table, which is a list of destination networks and the way to reach each one. When a packet arrives for another network, the router looks up the best match and forwards the packet to the next hop.

Each line of the table is a route. RouterOS shows a set of flags on each route that tell you where it came from and whether it is in use.

PC192.168.88.10packet for 10.1.1.5Routerrouting table lookupnext hop 192.168.1.2Next routerforwards on

How it works

The router matches the destination against its routes, picks the most specific one, and sends the packet to that gateway.

The routing table

/ip route print

A typical small router shows output like this.

 #      DST-ADDRESS        PREF-SRC        GATEWAY            DISTANCE
 0 ADS  0.0.0.0/0                          203.0.113.1               1
 1 ADC  192.168.88.0/24    192.168.88.1    bridge1                   0
 2 ADC  203.0.113.0/24     203.0.113.17    ether1                    0

Every route has a destination address, which is a network in prefix form. It also has a gateway, which is the next hop, either an IP address or an interface. The distance is a number that ranks routes from different sources.

Connected routes

When you add an IP address to an interface, RouterOS creates a connected route for that subnet by itself. You do not add it manually.

In the example above, the LAN and the WAN subnets are connected routes. They use the interface as the gateway, because the destination is directly reachable on that port. A connected route has distance 0.

If you remove the address or the interface goes down, the connected route disappears with it.

How a route is chosen

The router follows two rules in order.

  1. Longest prefix match. The route with the most specific destination wins. A route for a /24 network beats a route for a /16 that also contains the destination.
  2. Lowest distance. If two routes have the same prefix, the one with the lower distance is used.

The default route is 0.0.0.0/0. It matches every destination, so it is used only when nothing more specific matches.

Route sourceTypical distance
Connected0
Static1
Other sourcesSet by the protocol or by you

Route flags

The letters in front of each route are flags. They are the quickest way to see the state of a route.

FlagMeaning
AActive, the route is used for forwarding
DDynamic, created by the system and not by you
CConnected, created from an IP address on an interface
SStatic, added by an administrator
XDisabled
BBlackhole, matching packets are silently dropped
UUnreachable, matching packets are dropped with an error

The example output is in the version 6 style, and version 7 prints extra lowercase letters for the route source, so read the legend at the top of the print output. The combination tells the story. ADC is an active, dynamic, connected route, and AS is an active static route.

ADS is a dynamic route that behaves like a static one, such as a default route from a DHCP client.

A route without the A flag is not used. Its gateway may be unreachable, it may be disabled, or a better route may exist for the same prefix.

Exam tip

When traffic does not follow the path you expect, read the flags first, then check whether the route is active.

Gateway reachability

A route is useful only when its gateway can be reached. Normally the router has a connected route that covers the gateway address.

If the router has no way to reach the gateway address, the route is shown as inactive. Fix the connected route first, and the static route becomes active.

Version differences

On version 6, routes can carry a routing mark to select a separate table for policy routing. Version 7 changed the routing menus and uses named routing tables, so the exact attributes differ between the two versions. The basic ideas on this page are the same in both.

Note

Static route commands with dst-address and gateway look the same in version 6 and version 7, but advanced routing features are configured differently.

What to remember for the exam

Seven facts cover this topic.

  • A router picks the route with the longest prefix match for the destination.
  • If prefixes are equal, the lowest distance wins.
  • A connected route is created automatically when an interface gets an IP address.
  • Connected routes have distance 0, and static routes have distance 1 by default.
  • The default route is 0.0.0.0/0.
  • The A flag means active, D dynamic, C connected and S static.
  • A route is used only when it is active.

Common mistakes

These four mistakes are common.

Expecting the lowest distance to beat a longer prefix. The longest prefix always wins first, and distance is a tie breaker.

Adding a route for a connected network. The connected route already exists, so a second one is unnecessary.

Using a gateway that is not reachable. The route stays inactive until a connected route covers the gateway.

Ignoring the flags. A route that is not active is not used, even though it appears in the table.

Check yourself

Work through these three questions.

  • Which route does a router choose when two routes match a destination?

    It uses the route with the longest prefix match. If the prefixes are the same, it uses the route with the lowest distance.

  • How is a connected route created?

    RouterOS creates it automatically when you add an IP address to an interface. It uses distance 0 and the interface as its gateway.

  • What do the flags in ADC and AS tell you?

    ADC is an active, dynamic, connected route. AS is an active static route.

Topic 1 of 2 in Routing

Test yourself on Routing

The full MikroTik MTCNA question bank has 558 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by MikroTik. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.