Peering sessions
CLI reference:/routing/bgp/instance/routing/bgp/connection/routing/bgp/template/routing/bgp/session/routing/bgp/advertisements
A BGP session in RouterOS is built from three menus:
- The instance (
/routing/bgp/instance) holds the local AS number and the router ID. - The connection (
/routing/bgp/connection) describes a peer: its address, the role of the session, the address families, the filters and what to advertise. A connection connects to the peer and accepts the peer's connection. - The session (
/routing/bgp/session) is the read-only state that RouterOS creates when the peer answers.
Templates (/routing/bgp/template) hold parameters that
several connections share. The connection menu has the template parameters too, so a simple setup needs no
template.
An eBGP session exchanges routes between autonomous systems. It usually runs between directly connected
routers at the edge of the network. With the default settings, an eBGP session to a peer that is not on a
connected network does not start: set multihop
to yes for such peers, for example for eBGP between loopback addresses.
The AS_PATH attribute prevents routing loops: a router drops a route whose AS path contains its own AS
number. Some setups accept such routes on purpose, for example an MPLS L3VPN customer site that receives routes of
another site with the same AS number. The input.allow-as
parameter sets how many times the own AS number is allowed in the path.
By default, on eBGP sessions the router sends its own address as the next hop. Set
nexthop-choice to propagate to keep
the received next hop instead. The Nexthop selection page describes the rules.
Configure an eBGP session
Router1 (AS 65531) and Router2 (AS 65532) are connected on ether2, 10.0.12.0/30. Router1 advertises its
prefix 198.51.100.0/24 to Router2.
Router1:
/ip/address/add address=10.0.12.1/30 interface=ether2
/ip/firewall/address-list/add list=bgp-networks \
address=198.51.100.0/24
/routing/bgp/instance/add name=bgp1 as=65531 router-id=10.0.12.1
/routing/bgp/connection/add name=toR2 instance=bgp1 \
remote.address=10.0.12.2 local.role=ebgp \
output.network=bgp-networks output.network-blackhole=yes
Router2:
/ip/address/add address=10.0.12.2/30 interface=ether2
/routing/bgp/instance/add name=bgp1 as=65532 router-id=10.0.12.2
/routing/bgp/connection/add name=toR1 instance=bgp1 \
remote.address=10.0.12.1 local.role=ebgp
What the parameters do:
local.roleis mandatory. It isebgpfor a plain eBGP session,ibgporibgp-rrfor iBGP. The other values are the eBGP roles of route leak prevention.- The connection needs no remote AS number: the router learns it from the peer's OPEN message. Set
remote.asto accept only that AS: a peer with another AS number is refused, and the log showsInvalid remote AS (<received>), expected <remote.as>. output.networknames an address list with the prefixes to advertise. BGP advertises a prefix of the list only when the routing table has an active route with exactly the same prefix.output.network-blackhole=yesadds that route as a blackhole route with distance 255, so the prefix is advertised even when no other route for it exists. More specific routes, such as the connected networks inside the prefix, are still used for forwarding.- The local address is not set: for a peer on a connected network, the router uses its address on that network (see the local address section of this page).
On a router with the default firewall, accept TCP port 179 from the peer, see Allow routing protocols.
Check the session
The E flag shows an established session:
[admin@MikroTik] > /routing/bgp/session/print
Flags: E - ESTABLISHED
0 E name="toR2-1" instance=bgp1 remote.address=10.0.12.2 .as=65532
.id=10.0.12.2 .capabilities=mp,rr,enhe,gr,as4 .afi= .messages=1
.bytes=19 .eor="" local.address=10.0.12.1 .as=65531 .id=10.0.12.1
.cluster-id=10.0.12.1 .capabilities=mp,rr,enhe,gr,as4 .afi= .messages=2
.bytes=67 .eor="" output.procid=20 .network=bgp-networks input.procid=20
ebgp hold-time=3m keepalive-time=1m uptime=8s770ms
last-started=2026-12-02 13:43:21 prefix-count=0
The session is named after the connection with a number (toR2-1). Most values are grouped by prefix:
remote.* describes the peer (its AS, router ID, capabilities, address families, and the messages and
bytes received from it), local.* this router (the messages and bytes sent), output.* and input.* the
advertising and receiving side. hold-time and keepalive-time are the negotiated timers. prefix-count
is updated periodically, so it can stay at 0 for a short time after the session starts.
Router2 has installed the route:
[admin@MikroTik] > /ip/route/print where bgp
Flags: D - DYNAMIC; A - ACTIVE; b - BGP
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
DAb 198.51.100.0/24 10.0.12.1 main 20
The advertisements menu shows what Router1 sends to each peer:
[admin@MikroTik] > /routing/bgp/advertisements/print
Columns: DST, PEER, AFI, NEXTHOP
DST PEER AFI NEXTHOP
198.51.100.0/24 toR2-1 10.0.12.1
print detail adds the attributes of each advertised route (origin, AS path, local preference, MED,
communities).
Check and troubleshoot sessions
-
RouterOS creates the session entry when the peer answers. A peer that does not answer has no session entry. The log shows the connection attempts and state changes:
/log/print where topics~"bgp". -
When the peer closes the session or the session is stopped, the routes received on it are removed. The session entry stays, without the
Eflag, withlast-startedandlast-stopped. Disabling the connection removes its session entry. -
Changing a connection or template parameter, for example
hold-time,local.roleoroutput.network, restarts the sessions that use it. A newremote.asis checked at the next session start. -
output.last-notificationholds the last NOTIFICATION message the router sent,input.last-notificationthe last one it received, in hex. For example,FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0015030601is error code 6 (Cease), subcode 1 (maximum number of prefixes reached). -
A received prefix limit (
input.limit-process-routes-ipv4) closes the session with that Cease message when the peer sends more prefixes. The session gets thelimit-exceededflag and stays down, also when the limit is raised. Raise the limit if needed, then clear the flag:/routing/bgp/session/clear [find] flag=limit-exceeded -
/routing/bgp/session/stopcloses a session and keeps it down (stoppedflag). The routes of the session are removed. Start it again with/routing/bgp/session/clear [find] flag=stopped. -
/routing/bgp/session/refresh <session> afi=ipasks the peer to send all its routes again (ROUTE-REFRESH).resendsends the router's own routes to the peer again. -
To keep a copy of the routes sent to a peer, set
output.keep-sent-attributestoyes. Then/routing/bgp/session/dump-saved-advertisements <session> save-to=<file>writes them to a PCAP file. Without the setting, the command fails withoutput.keep-sent-attributes not enabled.
Choose the local address
local.address is the address the
session uses (update-source on other vendors' routers). When it is not set, the router chooses one and shows
it in the connection as local.default-address:
- eBGP without
multihop: the router's address on the network that the peer address belongs to. When the peer is not on a connected network, the connection is inactive with the commentcannot listen to incoming connections, missing 'local-address'. - iBGP, and eBGP with
multihop=yes: the highest /32 address of the router (a loopback address) when the router has one, on any interface. Without a /32 address, the address on the network of the peer, or another address of the router when the peer is not on a connected network.
When addresses are added or removed, the router chooses again and the connection moves to the new address. Set
local.address on iBGP sessions and on sessions between loopback addresses, so that a new /32 address on the
router does not move the session.
iBGP and route reflection
iBGP exchanges routes inside an AS. It carries the routes learned from eBGP peers across the network. An iBGP
session is multihop by default (multihop=yes in the session) and usually runs between loopback addresses that an
IGP such as OSPF makes reachable. The router resolves the next hops of iBGP routes through the IGP
routes. iBGP routes have distance 200.
With nexthop-choice set to
force-self, the router advertises its own address as the next hop instead. The peers then need no route to
the original next hop, for example in a small network without an IGP where iBGP runs on directly connected
addresses.
iBGP does not add the own AS number to the AS path, so the AS path cannot detect loops inside the AS. Instead, a router does not advertise a route learned from one iBGP peer to another iBGP peer. All iBGP routers of the AS therefore need a session with each other, a full mesh:
graph LR
R1 <--> R2
R2 <--> R3
R3 <--> R1
A full mesh needs n*(n-1)/2 sessions for n routers. A route reflector removes the need for it: the clients
peer only with the reflector, n-1 sessions in all, and the reflector passes the routes of each client to the
other clients.
graph TB
R2(R2 RR) <--> R1
R2 <--> R3
A connection with local.role=ibgp-rr makes the router a route reflector for the peers of that connection.
Because reflection breaks this iBGP rule, the reflector adds two attributes that prevent loops: CLUSTER_LIST,
with the reflector's cluster ID (the router ID when
cluster-id is not set), and ORIGINATOR_ID. The
reflector does not send a route back to the client it came from, and it keeps the next hop of reflected routes.
Dynamic sessions with a route reflector
A route reflector can accept sessions from a whole address range, so a new client needs no change on the reflector. Here R1 is the reflector (loopback 10.255.0.1) for clients R2, R3 and R4 (loopbacks 10.255.0.2 to 10.255.0.4), all in AS 65000:
graph LR
r1["<b>R1, RR</b><br />lo 10.255.0.1"] --- r2["<b>R2</b><br />lo 10.255.0.2"]
r2 --- r3["<b>R3</b><br />lo 10.255.0.3"]
r3 --- r4["<b>R4</b><br />lo 10.255.0.4"]
r4 --- r1
Prerequisites:
- Addresses on the links (
ether2,ether3) and OSPF on them, with an area namedbackbone(see OSPF).
On the route reflector, add the loopback address, advertise it in OSPF, and add a template and a connection that listens to the loopback range:
/ip/address/add address=10.255.0.1 interface=lo
/routing/ospf/interface-template/add area=backbone interfaces=lo passive
/routing/bgp/instance/add name=bgp1 as=65000 router-id=10.255.0.1
/routing/bgp/template/add name=rr-clients afi=, hold-time=1m
/routing/bgp/connection/add name=clients instance=bgp1 \
remote.address=10.255.0.0/24 listen=yes templates=rr-clients \
local.address=10.255.0.1 local.role=ibgp-rr
The connection takes its address families and hold time from the rr-clients template. The clients announce
only ip (the default), so these sessions carry IPv4 routes. With a range in
remote.address and listen=yes, it accepts a session from every address of the range.
A connection that listens to a range accepts sessions from any address in it. Do not use it where untrusted
hosts can reach that range, and protect the router with the firewall: many incoming sessions can overload it.
See the listen parameter.
On each client, add its loopback address and a connection to the reflector's loopback. On R2:
/ip/address/add address=10.255.0.2 interface=lo
/routing/ospf/interface-template/add area=backbone interfaces=lo passive
/routing/bgp/instance/add name=bgp1 as=65000 router-id=10.255.0.2
/routing/bgp/connection/add name=toRR instance=bgp1 \
remote.address=10.255.0.1 local.address=10.255.0.2 \
local.role=ibgp
Configure R3 and R4 the same way with their own loopback addresses (10.255.0.3 and 10.255.0.4). Then let R3 advertise 203.0.113.0/24:
/ip/firewall/address-list/add list=bgp-networks \
address=203.0.113.0/24
/routing/bgp/connection/set toRR output.network=bgp-networks \
output.network-blackhole=yes
The reflector has a session with each client. The sessions use the template's hold time:
[admin@MikroTik] > /routing/bgp/session/print
Flags: E - ESTABLISHED
0 E name="clients-1" instance=bgp1 remote.address=10.255.0.3 .as=65000
.id=10.255.0.3 .capabilities=mp,rr,enhe,gr,as4 .afi= .messages=2
.bytes=68 .eor="" local.role=ibgp-rr .address=10.255.0.1 .as=65000
.id=10.255.0.1 .cluster-id=10.255.0.1 .capabilities=mp,rr,enhe,gr,as4
.afi=, .messages=1 .bytes=19 .eor="" output.procid=20
input.procid=20 ibgp multihop=yes hold-time=1m keepalive-time=20s
uptime=15s40ms last-started=2026-12-02 13:43:51 prefix-count=1
1 E name="clients-2" instance=bgp1 remote.address=10.255.0.2 .as=65000
.id=10.255.0.2 .capabilities=mp,rr,enhe,gr,as4 .afi= .messages=1
.bytes=19 .eor="" local.role=ibgp-rr .address=10.255.0.1 .as=65000
.id=10.255.0.1 .cluster-id=10.255.0.1 .capabilities=mp,rr,enhe,gr,as4
.afi=, .messages=2 .bytes=83 .eor="" output.procid=21
input.procid=21 ibgp multihop=yes hold-time=1m keepalive-time=20s
uptime=14s580ms last-started=2026-12-02 13:43:52 prefix-count=0
2 E name="clients-3" instance=bgp1 remote.address=10.255.0.4 .as=65000
.id=10.255.0.4 .capabilities=mp,rr,enhe,gr,as4 .afi= .messages=1
.bytes=19 .eor="" local.role=ibgp-rr .address=10.255.0.1 .as=65000
.id=10.255.0.1 .cluster-id=10.255.0.1 .capabilities=mp,rr,enhe,gr,as4
.afi=, .messages=2 .bytes=83 .eor="" output.procid=22
input.procid=22 ibgp multihop=yes hold-time=1m keepalive-time=20s
uptime=13s640ms last-started=2026-12-02 13:43:53 prefix-count=0
R4 has R3's route through the reflector, with R3's loopback as the next hop:
[admin@MikroTik] > /ip/route/print where bgp
Flags: D - DYNAMIC; A - ACTIVE; b - BGP
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
DAb 203.0.113.0/24 10.255.0.3 main 200
To add another client, give it a loopback address in 10.255.0.0/24 and a connection to 10.255.0.1. The EVPN page uses the same method for its overlay, see BGP EVPN overlay and Use a route reflector instead of eBGP.
BGP unnumbered
RouterOS can establish a BGP session over a link that has no global IPv6 address and no configured peer address (a BGP unnumbered connection). The router finds the peer's IPv6 link-local address with IPv6 neighbor discovery (RFC 4861) and advertises IPv4 prefixes with an IPv6 next hop (RFC 8950). This suits networks with many point-to-point links, for example an eBGP underlay for EVPN.
A connection is unnumbered when remote.address
is empty and local.address is an interface.
It accepts one peer on that interface. The peer must send IPv6 router advertisements, so that the neighbor table lists it
with the R (router) flag. A router without global IPv6 addresses sends them after this setting,
on both routers:
/ipv6/nd/prefix/add prefix=none interface=ether3
Router1 (AS 65001) and Router4 (AS 65004) peer over ether3. Router1:
/routing/bgp/instance/add name=bgp1 as=65001 router-id=10.255.0.1
/routing/bgp/connection/add name=unnumbered instance=bgp1 \
local.address=ether3 local.role=ebgp afi=,
Router4:
/routing/bgp/instance/add name=bgp1 as=65004 router-id=10.255.0.4
/routing/bgp/connection/add name=unnumbered instance=bgp1 \
local.address=ether3 local.role=ebgp afi=,
The address family of an unnumbered connection is ipv6 by default. afi=ip,ipv6 lets it carry IPv4 routes
too. Router4 advertises 203.0.113.0/24:
/ip/firewall/address-list/add list=bgp-networks \
address=203.0.113.0/24
/routing/bgp/connection/set unnumbered output.network=bgp-networks \
output.network-blackhole=yes
On Router1, the neighbor table has Router4 as a router, and the connection uses the link-local address of
ether3:
[admin@MikroTik] > /ipv6/neighbor/print where interface=ether3
Flags: D - DYNAMIC; R - ROUTER
Columns: ADDRESS, MAC-ADDRESS, INTERFACE, VRF, STATUS
# ADDRESS MAC-ADDRESS INTERFACE VRF STATUS
0 DR fe80::4054:43ff:fe1c:5ad9 42:54:43:1C:5A:D9 ether3 main reachable
[admin@MikroTik] > /routing/bgp/connection/print
0 name="unnumbered" instance=bgp1 local.address=ether3
.default-address=fe80::8846:1eff:fe21:58a7%ether3 .role=ebgp
routing-table=main as=65001 afi=,
[admin@MikroTik] > /routing/bgp/session/print
Flags: E - ESTABLISHED
0 E name="unnumbered-1" instance=bgp1
remote.address=fe80::4054:43ff:fe1c:5ad9%ether3 .as=65004 .id=10.255.0.4
.capabilities=mp,rr,enhe,gr,as4 .afi=, .messages=2 .bytes=85 .eor=""
local.address=fe80::8846:1eff:fe21:58a7%ether3 .as=65001 .id=10.255.0.1
.cluster-id=10.255.0.1 .capabilities=mp,rr,enhe,gr,as4 .afi=,
.messages=1 .bytes=19 .eor="" output.procid=20 input.procid=20 ebgp
hold-time=3m keepalive-time=1m uptime=13s340ms
last-started=2026-12-02 13:44:13 prefix-count=0
The IPv4 route has Router4's link-local address as its gateway (the enhe capability, extended next hop
encoding):
[admin@MikroTik] > /ip/route/print where bgp
Flags: D - DYNAMIC; A - ACTIVE; b - BGP
Columns: DST-ADDRESS, GATEWAY, ROUTING-TABLE, DISTANCE
DST-ADDRESS GATEWAY ROUTING-TABLE DISTANCE
DAb 203.0.113.0/24 fe80::4054:43ff:fe1c:5ad9%ether3 main 20
Properties of all menus: /routing/bgp/instance,
/routing/bgp/connection,
/routing/bgp/template,
/routing/bgp/session,
/routing/bgp/advertisements.