Introduction
BGP (Border Gateway Protocol) on MikroTik RouterOS 7 uses an entirely rewritten routing engine compared to ROS 6. The new engine is more efficient, better handles large routing tables, and introduces significant configuration changes. This guide covers the new BGP configuration model.
Key Differences in RouterOS 7 BGP
| Feature | RouterOS 6 | RouterOS 7 |
|---|---|---|
| BGP instance | /routing bgp instance | /routing bgp template |
| Peer config | /routing bgp peer | /routing bgp connection |
| Network advertising | /routing bgp network | via filters |
| Route filters | basic | powerful scripting |
Step 1: Configure BGP Template (Router Identity)
# Set router AS number and router-id
/routing bgp template
add name=default as=65001 router-id=10.0.0.1Step 2: Add BGP Peer Connection
For a simple eBGP connection to your ISP:
/routing bgp connection
add name=ISP-Peer template=default remote.address=203.0.113.1 remote.as=65000 local.address=203.0.113.2 output.filter-chain=TO-ISP input.filter-chain=FROM-ISPStep 3: Route Filters
RouterOS 7 uses a new filter scripting language:
/routing filter rule
# Advertise only your own prefix
add chain=TO-ISP rule="if (dst == 192.168.0.0/16) { accept } else { reject }"
# Accept default route from ISP, reject everything else
add chain=FROM-ISP rule="if (dst == 0.0.0.0/0) { accept } else { reject }"Step 4: Advertise Your Networks
# Add connected network to BGP output
/routing bgp connection
set ISP-Peer output.network=192.168.0.0/16Or use more specific filter to control what gets announced:
/routing filter rule
add chain=TO-ISP rule="
if (dst == 192.168.1.0/24 || dst == 192.168.2.0/24) {
set bgp-communities 65001:100;
accept
}
reject
"iBGP Configuration
For connecting two routers within the same AS:
/routing bgp connection
add name=IBGP-R2 template=default remote.address=10.0.0.2 remote.as=65001 local.address=10.0.0.1Key difference: iBGP does NOT increment the as-path, so you need either:
- Full mesh between all iBGP routers, OR
- Route Reflector setup
Route Reflector Setup
Designate one router as the Route Reflector:
/routing bgp connection
add name=RR-Client1 template=default remote.address=10.0.0.3 remote.as=65001 route-reflect=yes cluster-id=10.0.0.1BGP Communities
Set and match communities for traffic engineering:
/routing filter rule
add chain=FROM-ISP rule="
if (bgp-communities includes 65000:200) {
set bgp-local-pref 200;
accept
}
"Verification and Troubleshooting
# View BGP sessions
/routing bgp connection print
/routing bgp session print
# View BGP routing table
/routing route print where bgp
# Check BGP advertisements
/routing bgp advertisement print
# Debug BGP events
/routing bgp connection monitor [find name=ISP-Peer] output=yesReal-World Multi-Homing Setup
Two ISPs, prefer ISP1, failover to ISP2:
/routing bgp connection
add name=ISP1 template=default remote.address=1.1.1.1 remote.as=65100 input.filter-chain=FROM-ISP1 output.filter-chain=TO-ISP
add name=ISP2 template=default remote.address=2.2.2.2 remote.as=65200 input.filter-chain=FROM-ISP2 output.filter-chain=TO-ISP
/routing filter rule
add chain=FROM-ISP1 rule="set bgp-local-pref 200; accept"
add chain=FROM-ISP2 rule="set bgp-local-pref 100; accept"