Mastering OSPF on MikroTik: Dynamic Routing for Multi-Site Networks
Well, hello again! It’s Emmanuel Corels here with Emmanuel Corels Creatives. By now, you’ve probably flexed your MikroTik muscles with VPNs, Hotspots, VLANs, and all sorts of goodies. But what about connecting multiple networks or offices together seamlessly without fiddling with static routes every time? That’s where OSPF (Open Shortest Path First) steps in—a powerful dynamic routing protocol that automatically figures out the best paths in your network. Let’s dive in!
Why OSPF?
OSPF is a link-state routing protocol widely used in enterprise networks. Instead of you manually configuring every route, OSPF routers exchange information about their links and build a complete map (or database) of the network topology. That means:
- Automatic Updates: If a link goes down or a new router pops up, OSPF recalculates routes on the fly.
- Scalability: Handles complex networks spanning multiple areas and subnets.
- Fast Convergence: Quickly detects changes and updates the routing table to prevent downtime.
- Standardized: Works across different vendors, not just MikroTik.
Basic OSPF Concepts
- Router ID: A unique identifier for each OSPF router, usually an IP address.
- Area: OSPF networks can be split into areas (like “0” for the backbone, plus more if needed).
- Hello Packets: Routers send these periodically to discover neighbors on the same network.
- LSA (Link-State Advertisement): Routers exchange these to share info about connected links.
- Cost: OSPF metric that helps determine the “shortest path.” In MikroTik, cost often depends on interface bandwidth or manual settings.
Setting Up OSPF on MikroTik
Pick a Router ID
MikroTik will typically auto-select your highest IP address as the Router ID if you don’t specify one. But it’s best practice to set it manually. Hop into Routing → OSPF (WinBox) or do:
/routing ospf instance set [find default=yes] router-id=1.1.1.1
Replace 1.1.1.1
with something unique in your network—often a loopback address.
Create an OSPF Instance
In newer RouterOS (v7+), you’ll see Routing → OSPF → Instances. By default, there’s a single “default” instance. You can keep that or create your own. Let’s just tweak the default for now, setting the Router ID and ensuring it’s enabled.
/routing ospf instance set [find name=default] router-id=1.1.1.1
Define OSPF Areas
By default, there’s an area called “backbone” (ID 0.0.0.0
). In many small/medium networks, you can stick with that single area. If you’re building a larger hierarchical design, create additional areas (like 0.0.0.1
, 0.0.0.2
) and connect them to the backbone area. For simplicity:
/routing ospf area add name=myArea area-id=0.0.0.1
Or just use the default backbone area if you want everything in a single area.
Advertising Networks
In RouterOS v6, you’d go under Routing → OSPF → Networks. In RouterOS v7, you’ll use Routing → OSPF → Interfaces or directly specify in the OSPF instance. The idea is: “Which networks or interfaces do you want OSPF to run on?”
If you want OSPF on, say, ether2
that’s in 192.168.10.0/24, do something like:
/routing ospf interface-template add networks=192.168.10.0/24 area=backbone
Or if you prefer, let OSPF discover everything on a certain interface:
/routing ospf interface-template add interface=ether2 area=backbone type=broadcast
Now OSPF will form adjacencies with any other OSPF routers on that subnet.
Checking Your Neighbors
Once you configure OSPF on two or more routers sharing a subnet, they’ll discover each other:
- In WinBox: Routing → OSPF → Neighbors.
- In CLI:
/routing ospf neighbor print
If everything’s configured right, you’ll see “Full” or “2-Way” states. That means adjacency is established, and they’re exchanging routes.
Viewing Routes
To confirm OSPF is actually populating your routing table, check:
/ip route print where ospf
You should see routes marked with “D o” (Dynamic OSPF). WinBox also shows them in IP → Routes, usually with an “Ao” or “O” flag. If you see those, OSPF is doing its job.
Handling Multiple Areas
In bigger setups, you might create additional areas to segment your network. The backbone area is always area 0 (0.0.0.0
). Additional areas could be 0.0.0.1
, 0.0.0.2
, etc.
- Assign each router’s interfaces to the correct area.
- Ensure at least one router acts as an Area Border Router (ABR) between the new area and the backbone. MikroTik automatically does this if it has interfaces in multiple areas.
Cost and Metric Tweaks
By default, OSPF calculates cost from interface speeds or defaults. You can manually set cost on an interface if you want to influence path selection:
/routing ospf interface-template set [find interface=ether2] cost=10
Lower cost = more preferred path. This helps you prefer certain links or shape the flow of traffic in more complex topologies.
Common Troubleshooting Tips
- Mismatched Area or Network: If your neighbors don’t show up, confirm both routers are in the same area and have overlapping networks configured.
- Different Subnet Masks: OSPF adjacency won’t form if one router sees 192.168.10.0/24 and the other sees 192.168.10.0/25, for example.
- Authentication: If you enable OSPF authentication, make sure both ends have the same password or key.
- Router ID Duplicates: Two routers can’t share the same Router ID; that’ll cause conflicts.
- Firewall Blocks: Check if you’re dropping OSPF multicast traffic (224.0.0.5 or 224.0.0.6) or if there’s a mismatch in interface “type” (broadcast vs. nbma, etc.).
Advanced OSPF Features
- Route Filtering: You can filter certain routes with distribute-lists or route filters if you only want some networks advertised.
- Summarization: In area border routers, summarize multiple subnets into a single route advertisement, reducing overhead.
- Virtual Links: If you need to connect an area to the backbone when there’s no direct link—use a virtual link as a workaround.
- NBMA Networks: On non-broadcast networks (like certain VPNs), you might have to configure neighbors manually.
Real-World Use Cases
-
Multi-Branch Office
Each site has its own MikroTik router, all connected over an MPLS or a VPN. OSPF shares route info so each office sees the rest automatically. -
Redundant Links
If you have two or more paths to the same destination, OSPF picks the best path and fails over quickly if one link fails. -
Dynamic Layer 3 Wireless or WISP
If you’re running a wireless ISP using MikroTik, OSPF can handle route changes as you add more towers or links.
Next Steps
- Dive deeper into RouterOS v7 OSPF specifics. The interface-based config changed slightly compared to older versions.
- Experiment with route redistribution (like from OSPF to BGP or static routes).
- Explore BFD (Bidirectional Forwarding Detection) to speed up failure detection in OSPF.
Final Thoughts on OSPF
OSPF might sound intimidating at first, but once you wrap your head around the concepts—neighbors, areas, LSAs, and costs—it’s a game-changer for multi-site or dynamically changing networks. No more guessing if your static routes are correct—OSPF automates it. Just pay attention to your area design, keep an eye on router IDs, and watch those logs if something doesn’t form an adjacency.
Have fun exploring the wonders of dynamic routing, and as always, don’t hesitate to reach out if you get stuck or want to show off your fancy new OSPF topologies. We’re all learning, one route at a time!
Explained with enthusiasm by
Emmanuel Corels – Admin, Emmanuel Corels Creatives