If you're managing more than two or three MikroTik routers, you've probably felt the pain of static routes. Add a new subnet? Touch every router. A link goes down? Traffic black‑holes until you notice. Scale to ten routers and static routes become a full‑time job.
OSPF (Open Shortest Path First) fixes all of that. It's a dynamic routing protocol that lets routers discover each other, share network information automatically, and re‑converge in seconds when a link fails. And with RouterOS v7, MikroTik completely rewrote the OSPF implementation – so if you're still using v6 syntax, this guide will get you up to speed.
By the end of this tutorial you'll have OSPF running across multiple routers, understand areas and costs, know how to redistribute routes, secure adjacencies with authentication, and even run OSPF over WireGuard VPN tunnels. Let's go.
What Is OSPF and Why Use It?
OSPF is a link‑state interior gateway protocol (IGP). Unlike RIP, which just counts hops, OSPF builds a complete map (topology database) of the network and uses Dijkstra's algorithm to calculate the shortest path to every destination. Here's why it beats static routes:
- Automatic convergence – When a link fails, OSPF re‑calculates paths in seconds without human intervention.
- Scalability – OSPF handles hundreds of routers using areas to keep things manageable.
- Loop‑free – The SPF algorithm guarantees loop‑free routing by design.
- Cost‑based – Routes are chosen by interface cost (usually based on bandwidth), not just hop count.
- Standards‑based – OSPF (RFC 2328) works between MikroTik, Cisco, Juniper, and any other vendor.
- Supports ECMP – Equal‑cost multi‑path lets you load‑balance across parallel links automatically.
If you're still adding /ip route add lines on every router, OSPF will change your life. And if you're running a multi‑site ISP or WISP with MikroRadius handling subscriber authentication, OSPF ensures your RADIUS traffic always finds the best path to the server – even during link failures.
OSPF Core Concepts (Quick Reference)
Before touching the CLI, let's nail down the terminology. Skip this if you're already comfortable with OSPF theory.
| Concept | What It Means |
|---|---|
| Router ID | A unique 32‑bit identifier for each OSPF router (looks like an IP, e.g. 1.1.1.1). Set it explicitly – don't let the router auto‑select. |
| Area | A logical grouping of routers and networks. Area 0 (backbone) is mandatory. All other areas must connect to it. |
| LSA (Link‑State Advertisement) | The packets routers send to describe their interfaces and neighbors. The collection of LSAs forms the LSDB (Link‑State Database). |
| Adjacency | A full relationship between two OSPF routers that have exchanged their complete LSDB. Not all neighbors become adjacent. |
| DR / BDR | Designated Router and Backup DR. On broadcast networks (Ethernet), one router is elected DR to reduce the number of adjacencies. The BDR is the backup. |
| Cost | A metric assigned to each interface. Lower cost = preferred path. Default formula: 100,000,000 / bandwidth. A 1 Gbps link has cost 1; a 100 Mbps link has cost 10. |
| Hello / Dead Interval | Hello packets are sent every 10 seconds (default on broadcast). If no hello is received for 40 seconds (dead interval), the neighbor is declared down. |
| SPF Algorithm | Shortest Path First (Dijkstra). Each router independently calculates the best path tree from its own perspective. |
| ABR | Area Border Router – a router that connects two or more areas and summarizes routes between them. |
| ASBR | Autonomous System Boundary Router – a router that redistributes external routes (static, BGP, connected) into OSPF. |
RouterOS v7 vs v6: The OSPF Syntax Changed Completely
If you've configured OSPF on RouterOS v6 before, forget everything. MikroTik moved from the legacy /routing ospf structure to a completely new hierarchy in v7. Here's what changed:
| v6 Path | v7 Path | Notes |
|---|---|---|
/routing ospf instance | /routing ospf instance | Still exists, but structure changed. Router ID is now set here. |
/routing ospf area | /routing ospf area | Now references an instance by name. |
/routing ospf network | Removed | Replaced by interface templates. |
/routing ospf interface | /routing ospf interface-template | This is the big change. You match interfaces to areas using templates. |
| N/A | /routing ospf static-neighbor | For NBMA networks where neighbors must be manually specified. |
The biggest gotcha: there is no more /routing ospf network command in v7. You use interface templates instead. This guide uses v7 syntax exclusively.
Prerequisites
- Two or more MikroTik routers running RouterOS v7.6+ (v7.16+ recommended for latest fixes).
- The
routingpackage installed (included by default on most RouterOS v7 builds; verify with/system package print). - Basic IP addressing already configured on all interfaces. If you need help, see our MikroTik beginner's setup guide.
- WinBox v3.40+ or SSH/terminal access to each router.
- A network diagram (even a rough sketch) showing which subnets connect where.
Lab Topology: 2‑Router OSPF Setup
We'll start simple. Two routers connected via an Ethernet link, each with their own LAN subnet:
┌─────────────────┠ether1↔ether1 ┌─────────────────â”
│ Router A │──────────────────────────────│ Router B │
│ ID: 1.1.1.1 │ 10.0.0.0/30 │ ID: 2.2.2.2 │
│ LAN: ether2 │ │ LAN: ether2 │
│ 192.168.1.0/24 │ │ 192.168.2.0/24 │
└─────────────────┘ └─────────────────┘
Goal: Devices on 192.168.1.0/24 should reach 192.168.2.0/24 (and vice versa) without any static routes.
Step 1: Assign IP Addresses
Skip this if your IPs are already configured.
Router A
/ip address add address=10.0.0.1/30 interface=ether1 comment="Link to Router B"
/ip address add address=192.168.1.1/24 interface=ether2 comment="LAN A"
Router B
/ip address add address=10.0.0.2/30 interface=ether1 comment="Link to Router A"
/ip address add address=192.168.2.1/24 interface=ether2 comment="LAN B"
WinBox path: IP → Addresses → Add New. Enter the address and select the interface from the dropdown.
Step 2: Create the OSPF Instance
The instance is the top‑level OSPF process. You must set a router ID – a unique 32‑bit value that identifies this router in OSPF. Best practice: use a loopback IP or a manually chosen value that won't change.
Router A
/routing ospf instance add name=ospf-main router-id=1.1.1.1
Router B
/routing ospf instance add name=ospf-main router-id=2.2.2.2
WinBox path: Routing → OSPF → Instances → Add New. Name = ospf-main, Router ID = 1.1.1.1 (or 2.2.2.2).
Why set the Router ID explicitly? If you don't, RouterOS picks the highest IP address on the router. If that IP changes (DHCP on WAN, for example), the Router ID changes and all adjacencies flap. Always hardcode it.
Step 3: Create the OSPF Area
Every OSPF network needs at least Area 0 (the backbone). For a simple two‑router setup, everything goes in Area 0.
Both Routers (identical command)
/routing ospf area add name=backbone area-id=0.0.0.0 instance=ospf-main
WinBox path: Routing → OSPF → Areas → Add New. Name = backbone, Area ID = 0.0.0.0, Instance = ospf-main.
Step 4: Add Interface Templates
This is where v7 differs most from v6. Instead of specifying networks, you create interface templates that tell OSPF which interfaces to activate on and which area they belong to.
Router A
/routing ospf interface-template add interfaces=ether1 area=backbone type=ptp
/routing ospf interface-template add interfaces=ether2 area=backbone type=broadcast passive
Router B
/routing ospf interface-template add interfaces=ether1 area=backbone type=ptp
/routing ospf interface-template add interfaces=ether2 area=backbone type=broadcast passive
WinBox path: Routing → OSPF → Interface Templates → Add New. Select the interface, choose the area, and set the network type.
Let's break down the key parameters:
interfaces=ether1– Which interface this template applies to. You can also use wildcards likeether*orall.area=backbone– Which OSPF area this interface belongs to.type=ptp– Point‑to‑point. Used for links between exactly two routers. Skips DR/BDR election → faster convergence.type=broadcast– Standard Ethernet behavior with DR/BDR election. Use for shared LAN segments with multiple routers.passive– The interface's subnet is advertised into OSPF, but no OSPF hello packets are sent. Essential for LAN interfaces where there are no other OSPF routers.
Step 5: Verify the OSPF Adjacency
Within 10–40 seconds (hello + dead interval), the routers should form an adjacency. Check with:
/routing ospf neighbor print
You should see output like this on Router A:
Flags: V - virtual; D - dynamic
0 D instance=ospf-main area=backbone address=10.0.0.2
router-id=2.2.2.2 state="Full" state-changes=6
adjacency=2m15s
The key thing to look for: state="Full". If it says 2-Way, ExStart, or Init, something is wrong (see Troubleshooting below).
WinBox path: Routing → OSPF → Neighbors. The state column should show Full.
Step 6: Verify Routes
On Router A, check the routing table:
/ip route print where routing-table=main
You should see an OSPF route to Router B's LAN:
dst-address=192.168.2.0/24 gateway=10.0.0.2 distance=110 routing-table=main
And on Router B, you'll see 192.168.1.0/24 via 10.0.0.1. That's it – OSPF is working. Devices on LAN A can now reach LAN B without a single static route.
WinBox path: IP → Routes. Look for routes with DAo flags (Dynamic, Active, OSPF).
OSPF Network Types Explained
Choosing the right network type is critical. Here's when to use each:
| Type | DR/BDR Election | Use Case | Hello Interval |
|---|---|---|---|
| broadcast | Yes | Standard Ethernet LAN with multiple routers | 10s |
| ptp (point‑to‑point) | No | Direct link between exactly 2 routers (recommended for /30 or /31 links) | 10s |
| nbma | Yes | Non‑broadcast multi‑access (Frame Relay, ATM) – rare today | 30s |
| ptmp (point‑to‑multipoint) | No | Hub‑and‑spoke wireless links (WISPs), partial mesh | 30s |
Pro tip: For point‑to‑point links (/30 or /31 subnets between two routers), always use type=ptp. It skips DR/BDR election, which means faster adjacency formation and fewer LSAs.
Passive Interfaces: When NOT to Send OSPF Hellos
You want OSPF to advertise your LAN subnets so other routers know how to reach them. But you do not want OSPF sending hello packets on those LAN interfaces – there are no OSPF routers there, and it wastes bandwidth and creates a security risk (anyone connecting could become an OSPF neighbor).
The solution: mark the interface template as passive.
/routing ospf interface-template add interfaces=ether2 area=backbone type=broadcast passive
Rules of thumb for passive interfaces:
- Make passive: LAN ports, client‑facing interfaces, WAN uplinks (if the ISP isn't running OSPF).
- Keep active (not passive): Inter‑router links, VPN tunnel interfaces where OSPF should form adjacencies.
Route Redistribution: Injecting External Routes into OSPF
Sometimes you need OSPF to advertise routes that aren't learned via OSPF – for example, a default route from your ISP, static routes to a partner network, or BGP routes from an upstream provider.
In RouterOS v7, redistribution is configured directly on the OSPF instance:
Redistribute Connected Routes
/routing ospf instance set ospf-main redistribute=connected
This advertises all directly connected subnets as OSPF external routes (Type 5 LSA). Be careful – this includes every interface with an IP, even your WAN.
Redistribute Static Routes
/routing ospf instance set ospf-main redistribute=static
Redistribute Both
/routing ospf instance set ospf-main redistribute=connected,static
Redistribute with Route Filters (Recommended)
Blindly redistributing everything is dangerous. Use routing filters to control exactly what gets advertised:
/routing filter rule add chain=ospf-out rule="if (dst == 0.0.0.0/0) { accept } else { reject }"
/routing ospf instance set ospf-main out-filter-chain=ospf-out redistribute=static
This redistributes only the default route, not every static route in your table.
WinBox path: Routing → OSPF → Instances → select your instance → set Redistribute and Out Filter Chain fields.
Multi‑Area OSPF: Scaling Beyond the Backbone
A single area works for small networks, but once you exceed ~50 routers or have geographically separated sites, you should split into multiple areas. This reduces the size of the LSDB and limits SPF recalculations to within each area.
Multi‑Area Topology Example
┌───────────────â”
│ Router C │
│ ABR │
│ ID: 3.3.3.3 │
Area 1 │ │ Area 0 (Backbone)
┌────────────────┤ ether2 ether1├────────────────â”
│ Branch LAN │ │ Core Network │
│ 192.168.3.0/24 └───────────────┘ │
│ ┌──────┴──────â”
│ │ Router A │
│ │ ID: 1.1.1.1│
│ └─────────────┘
Router C has one interface in Area 0 and another in Area 1 – making it an Area Border Router (ABR). It summarizes Area 1's routes into Area 0 and vice versa.
Configuring Multi‑Area (Router C – ABR)
# Instance (same on all routers)
/routing ospf instance add name=ospf-main router-id=3.3.3.3
# Create both areas
/routing ospf area add name=backbone area-id=0.0.0.0 instance=ospf-main
/routing ospf area add name=area1 area-id=0.0.0.1 instance=ospf-main
# Interface templates
/routing ospf interface-template add interfaces=ether1 area=backbone type=ptp
/routing ospf interface-template add interfaces=ether2 area=area1 type=broadcast passive
Stub Areas (Reducing Route Table Size)
If a branch office doesn't need to know about external routes (only a default route), make it a stub area:
/routing ospf area add name=area1 area-id=0.0.0.1 instance=ospf-main type=stub
Stub areas block Type 5 LSAs (external routes) and inject a default route instead. This dramatically reduces the routing table on branch routers. For even more reduction, use totally stubby areas (which also block Type 3 summary LSAs):
/routing ospf area add name=area1 area-id=0.0.0.1 instance=ospf-main type=stub no-summaries
WinBox path: Routing → OSPF → Areas → Add New → set Type to stub.
OSPF Authentication: Securing Adjacencies
Without authentication, anyone who plugs a router into your network could inject false routes. OSPF supports two authentication methods on MikroTik RouterOS v7:
Simple (Plain Text) Authentication
/routing ospf interface-template set [find where interfaces=ether1] auth=simple auth-key=MySecret123
Warning: The password is sent in clear text. Only use this on physically secured links where you need basic rogue‑router protection.
MD5 Authentication (Recommended)
/routing ospf interface-template set [find where interfaces=ether1] auth=md5 auth-key=MyStr0ngK3y auth-id=1
MD5 hashes the password with each OSPF packet. The auth-id (key ID) must match on both sides. This is the minimum recommended security for production networks.
Important: Both routers on a link must use the same auth type, key, and key ID. Mismatched authentication is the #1 reason adjacencies fail silently.
WinBox path: Routing → OSPF → Interface Templates → select the template → set Auth = md5, Auth Key, and Auth ID.
OSPF Over VPN Tunnels
Running OSPF over VPN tunnels is extremely common for multi‑site networks. We covered this in depth in our WireGuard + OSPF dynamic routing guide, but here's the summary.
OSPF Over WireGuard
First, set up the WireGuard tunnel between sites (see our site‑to‑site WireGuard guide). Then add the WireGuard interface to OSPF:
/routing ospf interface-template add interfaces=wg-site-b area=backbone type=ptp
Because WireGuard tunnels are point‑to‑point by nature, always use type=ptp. Adjust the cost if you want the tunnel to be a backup path:
/routing ospf interface-template set [find where interfaces=wg-site-b] cost=100
OSPF Over EoIP
EoIP creates a Layer 2 tunnel, so OSPF sees it like a regular Ethernet link:
/interface eoip add name=eoip-site-b remote-address=203.0.113.5 tunnel-id=1
/ip address add address=10.255.0.1/30 interface=eoip-site-b
/routing ospf interface-template add interfaces=eoip-site-b area=backbone type=ptp
MTU Considerations for Tunnels
VPN tunnels have lower MTU than physical Ethernet (e.g., WireGuard ≈ 1420, EoIP ≈ 1458, GRE ≈ 1476 vs Ethernet's 1500). If the MTU doesn't match between two OSPF neighbors, the adjacency will get stuck in ExStart state because Database Description packets exceed the MTU and get dropped.
Solutions:
- Set matching MTU on both ends of the tunnel.
- Or clamp MSS:
/ip firewall mangle add chain=forward protocol=tcp tcp-flags=syn action=change-mss new-mss=clamp-to-pmtu passthrough=yes
Monitoring OSPF: Essential Commands
These are the commands you'll use daily to verify and monitor OSPF:
View Neighbors and Their State
/routing ospf neighbor print
WinBox path: Routing → OSPF → Neighbors
View the Link‑State Database
/routing ospf lsa print
This shows all LSAs the router knows about. Type 1 = Router LSA, Type 2 = Network LSA, Type 3 = Summary, Type 5 = External.
View OSPF Routes in the Routing Table
/ip route print where routing-table=main ospf
View OSPF Interface Status
/routing ospf interface print
Shows which interfaces are running OSPF, their area, cost, DR/BDR status, and neighbor count.
View OSPF Instance Details
/routing ospf instance print detail
Shows router ID, redistribution settings, and whether the instance is running.
Complete 3‑Router Network Script
Here's a full working configuration for a 3‑router network with Area 0 and Area 1. Copy‑paste these into each router via terminal.
Router A (Core – Area 0 only)
# IP Addressing
/ip address add address=10.0.0.1/30 interface=ether1 comment="Link to Router B"
/ip address add address=192.168.1.1/24 interface=ether2 comment="LAN A"
# OSPF
/routing ospf instance add name=ospf-main router-id=1.1.1.1
/routing ospf area add name=backbone area-id=0.0.0.0 instance=ospf-main
/routing ospf interface-template add interfaces=ether1 area=backbone type=ptp
/routing ospf interface-template add interfaces=ether2 area=backbone type=broadcast passive
Router B (ABR – Area 0 + Area 1)
# IP Addressing
/ip address add address=10.0.0.2/30 interface=ether1 comment="Link to Router A"
/ip address add address=10.0.1.1/30 interface=ether3 comment="Link to Router C"
/ip address add address=192.168.2.1/24 interface=ether2 comment="LAN B"
# OSPF
/routing ospf instance add name=ospf-main router-id=2.2.2.2
/routing ospf area add name=backbone area-id=0.0.0.0 instance=ospf-main
/routing ospf area add name=area1 area-id=0.0.0.1 instance=ospf-main
/routing ospf interface-template add interfaces=ether1 area=backbone type=ptp
/routing ospf interface-template add interfaces=ether2 area=backbone type=broadcast passive
/routing ospf interface-template add interfaces=ether3 area=area1 type=ptp
Router C (Branch – Area 1 only)
# IP Addressing
/ip address add address=10.0.1.2/30 interface=ether1 comment="Link to Router B"
/ip address add address=192.168.3.1/24 interface=ether2 comment="LAN C"
# OSPF
/routing ospf instance add name=ospf-main router-id=3.3.3.3
/routing ospf area add name=area1 area-id=0.0.0.1 instance=ospf-main
/routing ospf interface-template add interfaces=ether1 area=area1 type=ptp
/routing ospf interface-template add interfaces=ether2 area=area1 type=broadcast passive
After applying these configs, run /routing ospf neighbor print on each router. You should see:
- Router A: 1 neighbor (Router B, Full)
- Router B: 2 neighbors (Router A and Router C, both Full)
- Router C: 1 neighbor (Router B, Full)
And every router should have routes to all three LAN subnets.
Troubleshooting OSPF Problems
OSPF is reliable once configured correctly, but the initial setup can trip you up. Here are the most common issues and their fixes.
Neighbor Stuck in Init or 2‑Way State
Symptom: /routing ospf neighbor print shows Init or 2-Way but never Full.
- 2‑Way on broadcast network: This is actually normal for DROther routers. Only the DR and BDR form Full adjacencies with other routers. If you only have 2 routers on the segment, both should be Full. If one is 2‑Way, check that both routers are on the same subnet and area.
- Init state: Hellos are being sent but not received by the other side. Check: (1) firewall isn't blocking OSPF (protocol 89), (2) interfaces are on the same subnet, (3) area IDs match.
# Check if OSPF protocol is being blocked
/ip firewall filter print where protocol=89
# Allow OSPF if needed
/ip firewall filter add chain=input protocol=ospf action=accept comment="Allow OSPF" place-before=0
Neighbor Stuck in ExStart or Exchange State
Symptom: Neighbor gets to ExStart but never progresses to Loading or Full.
Cause: Almost always an MTU mismatch. OSPF Database Description (DD) packets include the interface MTU. If the MTUs don't match, the routers refuse to proceed.
- Check both interfaces:
/interface print detail where name=ether1– look at themtuvalue. - Set matching MTU on both sides, or on VPN tunnels, explicitly set MTU to the tunnel's effective MTU.
Routes Not Appearing in the Table
Symptom: Adjacency is Full but you don't see expected routes.
- Missing interface template: The remote subnet's interface isn't added to OSPF. Add a template (even passive) for every interface whose subnet you want advertised.
- Wrong area: If subnets are in different areas, make sure the ABR has both areas configured.
- Route filtering: Check if an input filter is blocking routes:
/routing ospf instance print detail– look atin-filter-chain. - Stub area blocking externals: If the area is stub, external (Type 5) routes won't appear. Only the default route is injected.
Hello/Dead Interval Mismatch
Symptom: No adjacency forms at all – neighbors don't even appear.
Cause: Hello and dead intervals must match on both sides of a link. Default is hello=10, dead=40 for broadcast/ptp, and hello=30, dead=120 for nbma/ptmp.
# Check current intervals
/routing ospf interface print detail
# Set custom intervals if needed
/routing ospf interface-template set [find where interfaces=ether1] hello-interval=10 dead-interval=40
Area ID Mismatch
Symptom: Routers see each other's hellos (confirmed via packet sniffer) but don't form a neighbor relationship.
Fix: Both sides of a link must be in the same OSPF area. Verify with /routing ospf interface print.
Duplicate Router IDs
Symptom: Random adjacency flaps, routes appearing and disappearing.
Fix: Every router in the OSPF domain must have a unique Router ID. Check with /routing ospf instance print on all routers.
OSPF Adjacency Keeps Flapping
Possible causes:
- Unstable physical link (check
/interface monitor ether1for link drops). - CPU overload causing hello timeouts (check
/system resource print). - VPN tunnel instability – if the underlying WAN link drops, the OSPF tunnel goes down. Consider increasing the dead interval on VPN interfaces.
OSPF Best Practices for Production Networks
- Always set Router ID explicitly – Never rely on auto‑selection.
- Use point‑to‑point for /30 and /31 links – Faster convergence, fewer LSAs.
- Make LAN and WAN interfaces passive – Only active on inter‑router links.
- Use MD5 authentication – Prevents rogue routers from injecting bad routes.
- Keep Area 0 contiguous – If it gets split, use virtual links (but avoid them if possible).
- Summarize at ABRs – Reduces routing table size in other areas.
- Filter redistributed routes – Never blindly redistribute all connected or static routes.
- Monitor regularly – Check neighbor state and route counts as part of your daily operations.
- Document your OSPF design – Areas, router IDs, costs, and authentication keys should all be documented.
- Use VLAN segmentation – Combine OSPF with VLANs for clean network separation.
OSPF + MikroRadius: ISP and WISP Considerations
If you're running an ISP or WISP with multiple MikroTik routers and using MikroRadius for subscriber management and billing, OSPF becomes critical infrastructure:
- Reliable RADIUS reachability – OSPF ensures every NAS (Network Access Server) router can always reach the RADIUS server, even if a primary link fails.
- Scalable growth – Adding a new POP or tower? Just plug it in, add OSPF, and routes propagate automatically. No need to update static routes on every existing router.
- Combine with PPPoE – Your PPPoE servers authenticate against MikroRadius, and OSPF handles the routing between all your NAS routers and the central RADIUS server.
- Dual‑WAN resilience – Pair OSPF with dual‑WAN failover for maximum uptime.
Conclusion
OSPF transforms multi‑router MikroTik networks from a static‑route nightmare into a self‑healing, self‑discovering system. Once you've set the router ID, created your areas, and added interface templates, the routers handle everything else – path calculation, failover, and load balancing.
Here's what we covered:
- OSPF fundamentals: areas, router ID, cost, DR/BDR, LSA types.
- RouterOS v7 syntax: instances, areas, and interface templates (no more
/routing ospf network). - Step‑by‑step 2‑router setup with verification commands.
- Network types: broadcast, point‑to‑point, NBMA, point‑to‑multipoint.
- Passive interfaces to protect LAN segments.
- Route redistribution with filters.
- Multi‑area OSPF with stub areas for branch offices.
- MD5 authentication for adjacency security.
- Running OSPF over WireGuard and EoIP tunnels.
- A complete 3‑router script ready to deploy.
- Comprehensive troubleshooting for every common failure mode.
For more advanced VPN + routing setups, check our WireGuard + OSPF scalable VPN guide and the hub‑and‑spoke WireGuard topology. And if you're ready to automate subscriber management across all those routers, give MikroRadius a try – it handles the billing and authentication so you can focus on the network.