MikroTik RouterOS 7 BGP: Templates, Connections and Sessions - 夜莺博客

MikroTik RouterOS 7 BGP: Templates, Connections and Sessions

RouterOS v7 threw away the v6 BGP configuration model. There is no /routing bgp instance and no per-peer peer menu any more; instead you get a strict split between connections (how the session is built), templates (protocol behaviour) and sessions (the live state, read-only). Anyone migrating from v6 needs the mapping, and anyone deploying fresh needs to know which menu holds which knob.

The mental model

  • Template — all BGP protocol parameters: local AS, address families, filters, hold time, next-hop handling, BFD. Templates can inherit from other templates.
  • Connection — the transport and identity of a peer: remote address, which template to use, whether to connect and/or listen, and the local role.
  • Session — the live state of each peer (established, idle, active), used for monitoring, not configuration.
/routing/bgp/template set default as=65533
/routing/bgp/template add name=myAsTemplate as=65500 output.filter-chain=myAsFilter
/routing/bgp/template set default template=myAsTemplate

The default template must have your own AS set before anything works — this is the single most common v7 stumbling block. Router IDs come from /routing id; by default RouterOS picks the highest IP on an interface.

eBGP to an upstream

/routing/bgp/template
add name=ebgp-tpl as=65500 output.network=bgp-networks     input.filter-chain=ebgp-in output.filter-chain=ebgp-out

/routing/bgp/connection
add name=peer-AS64500 remote.address=203.0.113.1 remote.as=64500     local.role=ebgp templates=ebgp-tpl     connect=yes listen=yes

connect and listen control who initiates: both sides listening means either can open the session, which is usually what you want on a peering link. For multihop sessions, set local.address explicitly — that is the v7 equivalent of v6’s update-source.

iBGP and address families

/routing/bgp/template
add name=ibgp-tpl as=65500     afi=ip,ipv6,l2vpn,evpn     nexthop-choice=propagate     use-bfd=yes

/routing/bgp/connection
add name=peer-RR-01 remote.address=10.0.0.2 remote.as=65500     local.role=ibgp templates=ibgp-tpl     multihop=yes local.address=10.0.0.1

RouterOS v7 supports afi=ip,ipv6,l2vpn,l2vpn-cisco,vpnv4,vpnv6,evpn, which means the same platform can act as an EVPN PE or an L3VPN speaker. nexthop-choice matters in iBGP deployments: the default follows RFC 4271 behaviour, while propagate keeps the received next hop, which is what you want when the RR should not become a transit hop.

Filters, BFD and monitoring

/routing/filter/rule
add chain=ebgp-in rule="if (bgp-med ... ) { ... }"
# v7 filters are expression based; chain contents are referenced from the template

/routing/bgp/session print
/routing/bgp/session print detail where established=no
/routing/stats

use-bfd=yes in the template turns on BFD for failure detection, so a link that stops forwarding without dropping the TCP session is detected in milliseconds rather than after the hold time. For monitoring, /routing/bgp/session print shows the live peers, and /routing/stats exposes counters for all routing processes. Keep the output-filter chain strict: RouterOS will happily advertise more than you intended if the template’s output.network list references an address list you forgot to prune.

Related reading: Huawei VRP common commands and troubleshooting, BGP session stuck in Idle/Active and BGP communities configuration examples.

原文链接:https://help.mikrotik.com/docs/spaces/ROS/pages/30474256/Moving+from+ROSv6+to+v7+with+examples