Static Routing on MikroTik RouterOS
Routing is the process of deciding where to send a packet based on its destination IP address. RouterOS maintains a routing table — a list of known networks and how to reach them. This lesson covers static routes: routes you add manually.
The Routing Table
To see the current routing table:
/ip route printExample output:
Flags: X - disabled, A - active, D - dynamic, C - connect, S - static, r - rip, b - bgp, o - ospf
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADC 192.168.1.0/24 192.168.1.1 bridge 0
1 ADC 10.0.0.0/30 10.0.0.1 ether1 0
2 ADS 0.0.0.0/0 10.0.0.254 1Understanding the flags:
A— Active (this route is currently being used)D— Dynamic (added automatically, e.g., by DHCP client or routing protocol)C— Connected (created automatically when you add an IP address to an interface)S— Static (manually added by you)
The Default Route
The most important static route is the default route — also called the gateway of last resort. It tells the router where to send traffic when no more specific route exists (which is most Internet traffic).
The default route has destination 0.0.0.0/0, which matches every IP address (with the lowest priority — more specific routes always win).
Adding a Default Route
/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.254Here 10.0.0.254 is your ISP gateway address. Every packet destined for the Internet will be sent there.
Check Your Default Route
/ip route print where dst-address=0.0.0.0/0Adding Static Routes
The general syntax is:
/ip route add dst-address=<NETWORK/PREFIX> gateway=<NEXT-HOP-IP>Example: Route to a Remote Network
Suppose you have two offices connected via a VPN or leased line:
- Your office:
192.168.1.0/24 - Remote office:
192.168.2.0/24 - The gateway to reach the remote office:
10.10.10.2
/ip route add dst-address=192.168.2.0/24 gateway=10.10.10.2 comment=route-to-remote-officeNow packets going to 192.168.2.x will be sent to 10.10.10.2, which forwards them to the remote office.
Example: Multiple Hops
If you need to reach 172.16.0.0/16 through 192.168.1.254:
/ip route add dst-address=172.16.0.0/16 gateway=192.168.1.254Route Distance (Metric)
Every route has a distance value (also called administrative distance or metric). Lower distance = higher priority.
Default distances:
| Route Type | Default Distance |
|---|---|
| Connected | 0 |
| Static | 1 |
| eBGP | 20 |
| OSPF | 110 |
| RIP | 120 |
You can set the distance when adding a route:
/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.254 distance=1Using Distance for Backup Routes (Floating Static Routes)
You can add two routes to the same destination with different distances to create a primary/backup setup:
# Primary route (distance 1 — used first)
/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.254 distance=1
# Backup route (distance 5 — only used if primary is inactive)
/ip route add dst-address=0.0.0.0/0 gateway=192.168.100.1 distance=5RouterOS will always use the route with lower distance when both are active. If the primary gateway fails (and RouterOS detects this via the check-gateway feature), it automatically switches to the backup.
The check-gateway Feature
RouterOS can monitor whether a gateway is reachable and mark a route as inactive if it is not:
/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.254 check-gateway=pingWith check-gateway=ping, RouterOS periodically pings the gateway. If it stops responding, the route is marked inactive and the next-best route takes over.
Longest Prefix Match
When a packet arrives, RouterOS picks the most specific route (the longest prefix) that matches. For example:
- Route A:
10.0.0.0/8via gateway1 - Route B:
10.10.0.0/16via gateway2 - Route C:
10.10.10.0/24via gateway3
A packet going to 10.10.10.5 will use Route C (most specific, longest prefix /24).
A packet going to 10.10.5.5 will use Route B.
A packet going to 10.20.0.5 will use Route A.
Removing and Modifying Static Routes
Remove a route by number:
/ip route remove 2Remove a specific route:
/ip route remove [find dst-address=192.168.2.0/24]Modify a route:
/ip route set 2 gateway=10.10.10.3Disabling Routes
You can disable a route without removing it (useful for testing):
/ip route disable 2
/ip route enable 2A disabled route shows with X flag in print.
Testing Routing with ping and traceroute
Test if a destination is reachable:
/ping 192.168.2.1 count=4Trace the path packets take:
/tool traceroute 8.8.8.8This shows every hop along the path to the destination — very useful for diagnosing routing problems.
Viewing the Route Table With Filters
Show only static routes:
/ip route print where staticShow only active routes:
/ip route print where activeSummary
Static routing in RouterOS:
- View routes:
/ip route print - Add default route:
/ip route add dst-address=0.0.0.0/0 gateway=X.X.X.X - Add specific route:
/ip route add dst-address=NETWORK/PREFIX gateway=X.X.X.X - Lower distance = higher priority
- Use floating static routes (different distances) for backup paths
- Use
check-gateway=pingto automatically failover when a gateway goes down
