🚀 Launching your own ISP? Create a free account and get 1 router slot for life!
Back to all articles
Tutorial By MikroRadius Team

BGP on MikroTik: Beginner's Guide to Internet Edge Routing (2026)

Connect your network to the internet with full BGP control. Learn BGP basics, eBGP setup with upstream providers, prefix filtering, and route selection – all on MikroTik RouterOS.

If you run an ISP, data center, or multi‑homed business network, you've likely heard of BGP (Border Gateway Protocol). It's the routing protocol that runs the internet. On MikroTik RouterOS, BGP is powerful and accessible – but the learning curve can be steep. This beginner's guide breaks down BGP concepts and walks you through a practical eBGP setup with a single upstream provider, including prefix filtering and basic route manipulation.

What Is BGP and Why Use It?

BGP is a path‑vector protocol that exchanges routing information between autonomous systems (ASes). An AS is a network under a single administrative control, identified by a unique AS number (ASN).

You need BGP when:

  • You have your own public IP address space and want to announce it to the internet.
  • You connect to multiple ISPs (multi‑homing) for redundancy.
  • You want fine‑grained control over inbound and outbound traffic.
  • You're an ISP or large organisation peering with others.

BGP Basics: Key Concepts

eBGP vs. iBGP

  • eBGP (External BGP) – runs between different ASes (e.g., your network and your ISP).
  • iBGP (Internal BGP) – runs inside the same AS (e.g., between your edge routers).

This guide focuses on eBGP with a single upstream provider.

BGP Attributes

BGP uses attributes to decide the best path. The most common:

  • AS_PATH – list of ASes a route has traversed; shorter is generally better.
  • NEXT_HOP – the IP address to reach the destination.
  • LOCAL_PREF – influences outbound traffic (higher = more preferred).
  • MED (Multi‑Exit Discriminator) – influences inbound traffic (lower = more preferred).

Prerequisites

  • MikroTik router with RouterOS v7 (BGP in v7 is more stable and feature‑rich).
  • Your own ASN (public or private). Public ASNs are obtained from your regional internet registry (RIPE, ARIN, APNIC, etc.).
  • Your own public IP prefix (e.g., 203.0.113.0/24).
  • An upstream ISP that supports BGP peering and has provided you with peering details (their ASN, their router IP).
  • Basic understanding of IP routing.

Topology Example

  • Your ASN: 65001 (private) or 12345 (public).
  • Your prefix: 203.0.113.0/24.
  • WAN interface: ether1, IP 203.0.113.2/30.
  • ISP router IP: 203.0.113.1, ISP ASN=65000.
  • Your LAN: 192.168.1.0/24 (NAT for lab, but for real prefixes you'd use public IPs).

Step 1: Basic WAN Configuration

Ensure your router has IP reachability to your ISP's BGP neighbor. Usually, you'll have a /30 or /31 point‑to‑point link.

/ip address add address=203.0.113.2/30 interface=ether1
/ip route add dst-address=0.0.0.0/0 gateway=203.0.113.1 distance=1

Test connectivity:

/ping 203.0.113.1

Step 2: Enable BGP Instance

/routing bgp instance set default as=65001 router-id=203.0.113.2

router-id can be any unique IP (often a loopback or the WAN IP).

Step 3: Add a BGP Peer (eBGP)

/routing bgp peer add name=isp-peer remote-address=203.0.113.1 remote-as=65000 local-address=203.0.113.2 multihop=no

If the peer is directly connected, multihop=no works. For BGP over a loopback or multiple hops, set multihop=yes and ttl=2 or higher.

Step 4: Filtering – What to Accept from Your ISP

By default, BGP will accept all routes. That's potentially millions of routes, which can overwhelm low‑end routers. You need to filter what you accept.

/routing bgp peer set isp-peer in-filter=accept-isp

Create a filter that accepts only a default route, or a limited prefix list.

/routing filter add name=accept-isp chain=bgp-in rule="if (dst-len == 0) { accept } else { reject }"

For a more realistic network, you'd accept the ISP's full table or a default + their customer routes. MikroTik v7 uses a new routing filter syntax (similar to firewall rules).

Example – accept default route only:

/routing prefix-list add name=default-only
/routing prefix-list add name=default-only prefix=0.0.0.0/0
/routing bgp peer set isp-peer in-filter="accept default" 

Actually, in v7 you can create a simple filter:

/routing filter add chain=bgp-in prefix=0.0.0.0/0 action=accept
/routing filter add chain=bgp-in action=reject

Step 5: Announcing Your Own Prefix

You need to tell BGP to advertise your public IP block (203.0.113.0/24). First, add a static route for the prefix to null0 (prevents loops).

/ip route add dst-address=203.0.113.0/24 type=blackhole

Then add a BGP network advertisement:

/routing bgp network add network=203.0.113.0/24 synchronize=no

Now create an outbound filter to allow your prefix to be sent to the peer.

/routing filter add chain=bgp-out prefix=203.0.113.0/24 action=accept
/routing filter add chain=bgp-out action=reject

Apply the out‑filter to the peer:

/routing bgp peer set isp-peer out-filter=bgp-out

Step 6: Optional – Set Local Preference for Outbound Traffic

If you have two upstream ISPs, you can use local preference to prefer one over the other. For a single upstream, this is less critical.

/routing bgp peer set isp-peer default-local-pref=100

Higher local pref = more preferred for outbound routes.

Step 7: Check BGP Status

Verify the BGP session is established:

/routing bgp peer print status
/routing bgp peer print where name=isp-peer

Look for state=established. If it's idle or active, troubleshoot connectivity or ASN mismatches.

View received routes:

/routing route print where bgp-as-path
/routing bgp advertisements print

Step 8: Firewall Considerations for BGP

BGP uses TCP port 179. Ensure your firewall allows inbound and outbound TCP/179 between your router and the ISP peer.

/ip firewall filter add chain=input protocol=tcp dst-port=179 src-address=203.0.113.1 action=accept
/ip firewall filter add chain=input protocol=tcp src-port=179 dst-address=203.0.113.1 action=accept

Step 9: Graceful Script to Monitor BGP Session

Optionally, add a simple netwatch or script to alert you if BGP goes down.

/tool netwatch add host=203.0.113.1 timeout=5s up-script=":log info \"BGP peer up\"" down-script=":log error \"BGP peer down\""

Advanced: BGP Communities

ISPs often use BGP communities to signal actions (e.g., prepending, no‑export). For example, to ask your ISP not to advertise your prefix to other ASes, you might set community 65000:999. Check with your ISP.

To set a community on your outbound route:

/routing filter add chain=bgp-out prefix=203.0.113.0/24 action=set-bgp-communities communities=65000:666

Troubleshooting BGP on MikroTik

  • Session stays in Active/Connect: Check TCP connectivity (telnet to port 179). Wrong remote-AS or remote-address.
  • Session establishes but no routes: Verify inbound filter rules. Check that your ISP is actually sending routes (ask them).
  • Routes not being announced: Ensure you have a static route to null0 for your prefix and that synchronize=no (for eBGP). Also check outbound filter.
  • High memory usage: Full internet table has ~900k routes. Low‑end routers (hEX, RB750) cannot handle full table. Use a default route only or partial tables.

Full Table vs. Default Route

A full internet BGP table consumes large amounts of RAM and CPU. For most networks, receiving a default route from your ISP is sufficient. Only accept full tables if you're multi‑homing and need optimal routing.

To receive only a default route, set your inbound filter to accept 0.0.0.0/0 only, as shown earlier.

Real‑World Example: Small ISP with Single Uplink

Your ASN is 65001, you have a /24 from RIPE. Your upstream ISP gives you a /30 link and AS65000. Configure BGP as above, announce your /24, and receive their default route. You also NAT your customers behind your public /24 (or use CGNAT). This setup is common for WISPs and small ISPs.

Conclusion: BGP on MikroTik – Powerful but Manageable

BGP on RouterOS v7 is mature and widely used. For a single‑homing scenario, the configuration is straightforward: establish eBGP with your ISP, filter incoming routes (usually a default), and announce your own prefix. Start with the basics, then explore attributes, communities, and iBGP for internal routing. Always test in a lab environment before touching production.

Next steps: learn about BGP path selection tuning, route reflectors, or BGP with OSPF for internal redistribution. For advanced filtering, study MikroTik's routing filter syntax in the official documentation.

Was this article helpful?