Skip to main content
Version: 7.26

Moving from ROSv6 to ROSv7

This page describes what works differently in RouterOS v7 routing compared with v6, and how the v7 configuration looks. To upgrade a router and to see what the upgrade converts automatically, read Upgrading to RouterOS v7.

Routes go to the main routing table, as in v6. The /routing/route menu shows the routes of all address families, including routes that a filter rejected, with all their attributes. The /ip/route and /ipv6/route menus add static routes and show only the basic attributes. The IP Routing page explains routing in general.

Routing tables and policy routing​

A routing table must exist in /routing/table before a route, a rule or a mangle rule can refer to it. A route that names a table that does not exist fails with input does not match any value of routing-table. Set fib on the table when its routes should be used for forwarding.

Routing rules are in /routing/rule (in v6, /ip route rule). The following example sends traffic to 8.8.8.8 to the gateway 10.0.12.2 on ether4 instead of the default route. The @main suffix resolves the gateway in the main table:

/routing/table/add name=myTable fib
/routing/rule/add dst-address=8.8.8.8 action=lookup-only-in-table \
table=myTable
/ip/route/add dst-address=8.8.8.8 gateway=10.0.12.2@main \
routing-table=myTable

Check the route in the new table:

[admin@MikroTik] > /routing/route/print where routing-table=myTable
Flags: A - ACTIVE; s - STATIC
Columns: DST-ADDRESS, GATEWAY, AFI, ROUTING-TABLE, DISTANCE, SCOPE,
TARGET-SCOPE, IMMEDIATE-GW
DST-ADDRESS GATEWAY AFI ROUTING-TABLE D SCOPE TA IMMEDIATE-GW
As 8.8.8.8/32 10.0.12.2 ip myTable 1 30 10 10.0.12.2%ether4

Mark routing with mangle​

Mangle can mark packets with a routing mark, as in v6. Do not mark traffic to the router's own addresses: the router then does not answer it. For example, in a router with two internet connections:

/routing/table/add name=toWAN1 fib
/ip/address
add address=192.168.1.1/24 interface=LAN
add address=198.51.100.2/24 interface=WAN1
add address=203.0.113.2/24 interface=WAN2
/ip/route
add gateway=198.51.100.1@main routing-table=toWAN1
add gateway=203.0.113.1
/ip/firewall/mangle
add chain=prerouting in-interface=LAN action=mark-routing \
new-routing-mark=toWAN1

A packet from the LAN to the router's address 192.168.1.1 gets the mark and is looked up in toWAN1. The only route in that table is the default route, so the router does not answer. Exclude the router's own addresses from the mangle rule:

/ip/firewall/mangle
set [find new-routing-mark=toWAN1] dst-address-type=!local

To check, ping the router's LAN address 192.168.1.1 from a device in the LAN.

Nexthop lookup​

In v6, a router keeps one gateway object for each gateway address. The following v6 example shows the effect:

/ip route add dst-address=10.0.1.0/24 gateway=10.0.0.1 scope=50 \
target-scope=30 comment=A
/ip route add dst-address=10.0.2.0/24 gateway=10.0.0.1 scope=30 \
target-scope=20 comment=B
/ip route add dst-address=10.0.0.0/24 gateway=WHATEVER scope=20 \
comment=C

The gateway 10.0.0.1 is resolved recursively through route C, with the smallest referring scope (scope 20 from route B), and both routes are active. Changing route A to target-scope=10 makes the gateway of route B inactive.

In v7, the router keeps several gateway objects per address, one for each combination of scope and gateway check. A change to the target-scope or the gateway check of one route does not affect other routes. The same example in v7, with 10.0.12.2 as a directly connected gateway:

/ip/route
add dst-address=10.0.0.0/24 gateway=10.0.12.2 scope=20 comment=C
add dst-address=10.0.1.0/24 gateway=10.0.0.1 scope=50 target-scope=30 \
comment=A
add dst-address=10.0.2.0/24 gateway=10.0.0.1 scope=30 target-scope=20 \
comment=B
set [find comment=A] target-scope=10

Route A becomes inactive, because route C, with scope 20, is out of reach for a target scope of 10. Route B stays active:

[admin@MikroTik] > /ip/route/print where comment~"^[ABC]\$"
Flags: I - INACTIVE, A - ACTIVE; s - STATIC
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
# DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
;;; C
3 As 10.0.0.0/24 10.0.12.2 main 1
;;; A
4 Is 10.0.1.0/24 10.0.0.1 main 1
;;; B
5 As 10.0.2.0/24 10.0.0.1 main 1

OSPF​

OSPFv2 and OSPFv3 are configured in one menu, /routing/ospf. A new router has no OSPF instance or area. Create an instance for each version and an area in each instance, then interface templates that put interfaces into the areas. A template selects interfaces by name (interfaces=) or by network (networks=):

/routing/ospf/instance
add name=v2inst version=2 router-id=10.255.255.1
add name=v3inst version=3 router-id=10.255.255.1
/routing/ospf/area
add name=backbone_v2 area-id=0.0.0.0 instance=v2inst
add name=backbone_v3 area-id=0.0.0.0 instance=v3inst
/routing/ospf/interface-template
add networks=192.168.0.0/24 area=backbone_v2
add networks=2001:db8::/64 area=backbone_v3
add interfaces=ether1 area=backbone_v3

RouterOS creates the dynamic entries in /routing/ospf/interface from the templates. The neighbors appear in /routing/ospf/neighbor. Virtual links are added in /routing/ospf/interface.

redistribute selects the routes OSPF advertises as external routes, and a routing filter in out-filter-chain can reject them or change their attributes. For example, to advertise only the static routes from 192.168.0.0/16:

/routing/ospf/instance
set v2inst redistribute=static out-filter-chain=ospf_out
/routing/filter/rule
add chain=ospf_out rule="if (dst in 192.168.0.0/16) {accept}"

A chain rejects every route that no rule accepts. When out-filter-chain is set and redistribute is not, the filter gets all active routes of the router, including connected routes. In that case, match the protocol in the filter:

/routing/ospf/instance
set v2inst !redistribute
/routing/filter/rule
add chain=ospf_out \
rule="if (protocol static && dst in 192.168.0.0/16) {accept}"

The OSPF section has a complete configuration, the default route, area types and troubleshooting.

BGP​

BGP is configured in four menus instead of the v6 instance and peer menus:

A connection needs at least an instance, the remote address and the local role. A connection without instance or local.role fails with missing value(s) of argument(s) instance local.role. The remote AS is optional: without it, RouterOS learns the AS from the neighbor's OPEN message. Set remote.as only to accept the connection from that AS alone.

/routing/bgp/instance
add name=bgp1 as=65002 router-id=10.0.12.1
/routing/bgp/connection
add name=to-isp instance=bgp1 remote.address=10.0.12.2 \
local.role=ebgp

The role is mandatory: ebgp or ibgp, or one of the more specific roles such as ebgp-customer and ebgp-provider (RFC 9234). connect and listen decide whether the router opens the connection, accepts it, or both. With a network as the remote address and listen=yes, the connection accepts sessions from every address in the network, for example from all iBGP neighbors in the subnet 10.0.13.0/24:

/routing/bgp/connection
add name=ibgp-peers instance=bgp1 remote.address=10.0.13.0/24 \
listen=yes local.role=ibgp

Each session gets the name of its connection with a number, for example ibgp-peers-1. A multihop session can need local.address, as update-source was used in v6.

The connection and template settings are grouped into input. and output. parameters, for example output.filter-chain=myBgpChain. A template can inherit the settings of another template with templates:

/routing/bgp/template
add name=myAsTemplate as=65500 output.filter-chain=myAsFilter
set default templates=myAsTemplate

input.affinity and output.affinity decide which routing process handles the input and output of a session, for example alone (a process for each session, for routers with many cores and many peers) or main. The connection reference lists the values.

On a router with the default firewall, accept TCP port 179 from the neighbor when the neighbor opens the connection. See Allow routing protocols.

Routing filters for BGP​

Set the filters on the connection or the template: output.filter-chain and output.filter-select for advertised routes, input.filter for received routes. The input.accept-* parameters (input.accept-nlri, input.accept-communities and others) drop unwanted prefixes before they are stored. Routes that input.filter rejects stay in memory and show as filtered in /routing/route. Routes that were stored before a change to input.accept-nlri stay until the session restarts.

The following filter accepts prefixes from 192.168.0.0/16 unchanged. For other prefixes, it lowers the local preference by 1 and sets the IGP metric from the OSPF external metric. The connection also accepts only the prefixes in the address list bgp_list:

/ip/firewall/address-list
add list=bgp_list address=192.168.1.0/24
add list=bgp_list address=192.168.0.0/24
add list=bgp_list address=172.16.0.0/24
/routing/filter/rule
add chain=bgp_in rule="if (dst in 192.168.0.0/16) {accept}"
add chain=bgp_in \
rule="set bgp-local-pref -1; set bgp-igp-metric ospf-ext-metric; accept"
/routing/bgp/connection
set to-isp input.filter=bgp_in input.accept-nlri=bgp_list

A chain rejects every route that no rule accepts.

Without output.network and output.redistribute, a connection advertises no routes.

warning

output.redistribute without output.filter-chain advertises every route of the selected types. With output.redistribute=connected, that includes networks such as the management network. Set an output filter that accepts only the routes to advertise.

Networks​

v7 has no network menu. Put the networks to advertise into an address list and name the list in output.network. In v6:

/routing bgp network add network=192.168.0.0/24 synchronize=yes
/ip route add dst-address=192.168.0.0/24 type=blackhole

In v7:

/ip/firewall/address-list
add list=bgp-networks address=192.168.0.0/24
/ip/route
add dst-address=192.168.0.0/24 blackhole
/routing/bgp/connection
set to-isp output.network=bgp-networks

A network is advertised only while the router has an active route to it. With output.network-blackhole=yes, RouterOS adds a blackhole route for each network in the list, so the /ip/route line is not needed:

/routing/bgp/connection
set to-isp output.network-blackhole=yes

Each connection can advertise its own list of networks.

Monitor BGP​

/routing/bgp/session/print shows the state of each session. The routes a connection advertises are listed, with the session name in the PEER column, in /routing/bgp/advertisements:

[admin@MikroTik] > /routing/bgp/advertisements/print
Columns: DST, PEER, AFI, NEXTHOP
DST PEER AFI NEXTHOP
192.168.0.0/24 to-isp-1 ip 10.0.12.1

To keep the attributes of the advertised routes, set output.keep-sent-attributes=yes on the connection and restart it. On a session that started before the setting, dump-saved-advertisements fails with output.keep-sent-attributes not enabled:

/routing/bgp/connection
set to-isp output.keep-sent-attributes=yes
disable to-isp
enable to-isp

When the session is established again, dump-saved-advertisements writes the advertisements to a pcap file in /file:

/routing/bgp/session
dump-saved-advertisements [find] save-to=bgp-out.pcap

/routing/stats/process shows the routing processes and their memory use, including the BGP sessions:

[admin@MikroTik] > /routing/stats/process/print
Columns: TASKS, PRIVATE-MEM-BLOCKS, SHARED-MEM-BLOCKS, PSS, RSS
# TASKS PRIVATE-M SHARED-ME PSS RSS
0 routing tables 1280.0KiB 2048.0KiB 783.0KiB 3908.0KiB
rib
1 fib 256.0KiB 0 685.0KiB 3732.0KiB
2 routing policy configuration 768.0KiB 512.0KiB 698.0KiB 3560.0KiB
3 configuration and reporting 512.0KiB 1024.0KiB 737.0KiB 3832.0KiB
4 BFD service 256.0KiB 0 633.0KiB 3480.0KiB
5 ospf 1280.0KiB 768.0KiB 789.0KiB 3772.0KiB
6 pimsm 256.0KiB 0 645.0KiB 3492.0KiB
7 ldp 256.0KiB 256.0KiB 678.0KiB 3656.0KiB
8 rip 768.0KiB 512.0KiB 705.0KiB 3680.0KiB
9 BGP service 256.0KiB 256.0KiB 676.0KiB 3596.0KiB
10 fantasy 256.0KiB 0 632.0KiB 3472.0KiB
11 isis 512.0KiB 768.0KiB 701.0KiB 3616.0KiB
12 evpn 256.0KiB 0 632.0KiB 3472.0KiB
13 bgp-IP-10.0.12.2 512.0KiB 512.0KiB 850.0KiB 3908.0KiB
bgp-output-10.0.12.2

The bgp-IP-10.0.12.2 and bgp-output-10.0.12.2 lines belong to the session with 10.0.12.2.

Routing filters​

Routing filter rules in /routing/filter/rule use a script-like syntax. A rule can have the form "if .. then", which sets attributes or applies an action when the condition matches. A rule that does not accept or reject the route passes it to the next rule of the chain, so the changes of several rules add up in order, like firewall rules. Writing one set per rule makes the order of the changes visible.

To accept a static default route:

/routing/filter/rule
add chain=ospf_in rule="if (dst==0.0.0.0/0 && protocol static) { accept }"

The v6 rule /routing filter add chain=ospf_in prefix=172.16.0.0/16 prefix-length=24 protocol=static action=accept is the following rule in v7:

/routing/filter/rule
add chain=ospf_in \
rule="if (dst in 172.16.0.0/16 && dst-len==24 && protocol static) { accept }"

To set the MED and prepend the AS path for /24 prefixes from 172.16.0.0/16:

/routing/filter/rule
add chain=BGP_OUT \
rule="if (dst-len==24 && dst in 172.16.0.0/16) { set bgp-med 20; set bgp-path-prepend 2; accept }"

To match a range of prefix lengths:

/routing/filter/rule
add chain=BGP_OUT \
rule="if (dst-len>13 && dst-len<31 && dst in 172.16.0.0/16) { accept }"

Filter rules match and set communities, large communities and extended communities:

/routing/filter/rule
add chain=bgp_in rule="set bgp-large-communities 200001:200001:10"

When many rules use the same communities, define them once in a list (community-list, community-large-list or community-ext-list) and use the list name:

/routing/filter/community-large-list
add list=myLargeComSet communities=200001:200001:10
/routing/filter/rule
add chain=bgp_in rule="append bgp-large-communities myLargeComSet"

The route target is an extended community, so match or change it through the extended communities:

/routing/filter/rule
add chain=bgp_in rule="set bgp-ext-communities rt:327824:20"

The Route Selection and Filtering page describes the rule syntax.

RPKI​

RouterOS is an RTR client: it connects to an RPKI validator and receives route origin data. A routing filter checks routes against an RPKI group with rpki-verify and matches the result with rpki, for example if (rpki invalid) { reject }. The RPKI page has the configuration.

RIP​

Create a RIP instance with the routes it redistributes and whether it advertises a default route, then an interface template for the interfaces RIP runs on. v7 needs no network entries:

/routing/rip/instance
add name=instance1 originate-default=never redistribute=connected,static
/routing/rip/interface-template
add interfaces=ether1 instance=instance1

Configure the neighbor router in the same way. On a router with the default firewall, accept UDP port 520 on the RIP interface, see Allow routing protocols.

v7 has no prefix lists. Filter RIP routes with routing filters.