OSPF Configuration
OSPF Configuration
Section titled “OSPF Configuration”This guide covers practical RouterOS 7 OSPF configuration: building multi-area networks with interface-template, controlling DR/BDR election on broadcast segments, and redistributing external routes into OSPF using routing filters.
RouterOS 7 replaces the legacy /routing ospf interface and /routing ospf network menus with /routing ospf interface-template. All configuration examples on this page use RouterOS 7 syntax.
Multi-Area Configuration
Section titled “Multi-Area Configuration”Instance and Area Setup
Section titled “Instance and Area Setup”Every OSPF deployment starts with an instance and at least one area. The instance holds global parameters; areas define the topology segments.
# Create OSPF instance/routing ospf instanceadd name=ospf1 version=2 router-id=1.1.1.1
# Backbone area (required)/routing ospf areaadd name=backbone area-id=0.0.0.0 instance=ospf1The router-id must be unique across the OSPF domain. Use a loopback address or a stable interface address rather than a transit IP that may be removed during maintenance.
Interface-Template
Section titled “Interface-Template”Interface-templates replace per-interface OSPF configuration. A template matches by interface name or network prefix and applies OSPF participation to all matching interfaces.
/routing ospf interface-template# Match by interface nameadd interfaces=ether1 area=backbone
# Match all interfaces with addresses in a rangeadd networks=10.0.0.0/8 area=backbone
# Point-to-point link — disables DR/BDR election, faster convergenceadd interfaces=sfp1 area=backbone network-type=point-to-point
# Passive: advertise the prefix but do not form OSPF neighborsadd interfaces=lo0 area=backbone passive=yesPassive interfaces are appropriate for loopbacks, management interfaces, and LAN segments where no OSPF neighbors exist but the prefix must be visible in the routing domain.
Adding Non-Backbone Areas
Section titled “Adding Non-Backbone Areas”/routing ospf areaadd name=area1 area-id=0.0.0.1 instance=ospf1add name=area2-stub area-id=0.0.0.2 instance=ospf1 type=stubadd name=area3-nssa area-id=0.0.0.3 instance=ospf1 type=nssa
/routing ospf interface-templateadd interfaces=ether2 area=area1add interfaces=ether3 area=area2-stubadd interfaces=ether4 area=area3-nssaA router becomes an ABR automatically when its interface-templates span multiple areas including the backbone. No explicit ABR designation is required.
For detailed area type behavior (stub, totally stubby, NSSA), see OSPF Area Types.
DR/BDR Election
Section titled “DR/BDR Election”Why DR/BDR Exists
Section titled “Why DR/BDR Exists”On broadcast multi-access segments (Ethernet, Wi-Fi), every pair of OSPF routers would need a full adjacency without DR/BDR, resulting in n(n-1)/2 adjacencies on a segment with n routers. The designated router and backup designated router reduce this to n adjacencies: every router forms adjacency only with the DR and BDR.
The DR redistributes LSAs to all routers on the segment using the AllSPFRouters multicast address 224.0.0.5. The BDR monitors the DR and takes over if it fails, using the AllDRouters address 224.0.0.6.
Election Mechanics
Section titled “Election Mechanics”Election runs once when OSPF starts on a segment (during the Wait period, which equals the dead-interval). The router with the highest priority wins the DR role; the second-highest becomes BDR. When priorities are equal, the highest router-id breaks the tie.
| Priority | Election outcome |
|---|---|
| 0 | Router is ineligible — never becomes DR or BDR |
| 1 | Default — participates in election |
| 2–254 | Higher values preferred |
| 255 | Maximum — will win any election |
OSPF DR/BDR elections are non-preemptive. If a higher-priority router comes online after election has completed, it does not displace the current DR. The only way to force re-election is to reset OSPF adjacencies on the segment.
Controlling Election Outcome
Section titled “Controlling Election Outcome”Set priority on the interface-template for each router on the segment.
Router that should always be DR (distribution switch or core router):
/routing ospf interface-templateadd interfaces=bridge-lan area=backbone priority=200Router that should be BDR (secondary distribution router):
/routing ospf interface-templateadd interfaces=bridge-lan area=backbone priority=100Router that should never be DR or BDR (access layer, spoke site):
/routing ospf interface-templateadd interfaces=bridge-lan area=backbone priority=0All routers on the same broadcast segment must use the same hello-interval and dead-interval, otherwise adjacencies will not form.
Network Types and DR/BDR
Section titled “Network Types and DR/BDR”| Network type | DR/BDR election | Use case |
|---|---|---|
broadcast | Yes | Ethernet LAN, default |
point-to-point | No | Two-router WAN links |
nbma | Yes | Frame Relay, ATM |
ptmp | No | Hub-and-spoke point-to-multipoint |
ptmp-broadcast | No | Point-to-multipoint broadcast mode |
On point-to-point links, DR/BDR election does not run — the two endpoints form a direct Full adjacency, which also improves convergence. Always configure network-type=point-to-point on /30 and /31 transit links.
/routing ospf interface-templateadd interfaces=ether1 area=backbone network-type=point-to-pointVerifying DR/BDR State
Section titled “Verifying DR/BDR State”# Show all OSPF neighbors including DR/BDR roles/routing ospf neighbor print
# Detail view: shows DR and BDR IP for each neighbor/routing ospf neighbor print detail
# Show interface state including current DR/BDR on each segment/routing ospf interface print detailThe neighbor output includes a role field showing whether the neighbor is the DR, BDR, or DROther on that segment. Your own router’s DR/BDR role appears in the interface detail output under dr and bdr fields.
Route Redistribution
Section titled “Route Redistribution”Redistribution in RouterOS 7
Section titled “Redistribution in RouterOS 7”RouterOS 7 separates what to redistribute from how to filter it. The OSPF instance redistribute parameter selects which route classes enter the redistribution pipeline; a routing filter chain (attached via out-filter-chain) controls which individual routes are accepted and sets their external attributes.
redistribute value | Source |
|---|---|
connected | Directly connected interfaces |
static | Static routes |
bgp | Routes learned from BGP |
rip | Routes learned from RIP |
vpn | VPN routes |
none | Disable redistribution (default) |
Multiple sources are specified as a comma-separated list.
Redistribute Connected and Static Routes
Section titled “Redistribute Connected and Static Routes”/routing ospf instanceset ospf1 redistribute=connected,staticWithout an output filter, all routes from the selected classes are redistributed with the default external metric and type 2. This is acceptable for small networks but becomes unmanageable when redistributing large BGP tables or overlapping statics.
Controlling Redistribution with Routing Filters
Section titled “Controlling Redistribution with Routing Filters”Attach a filter chain to the instance to select which routes are advertised and set external attributes on each route.
/routing ospf instanceset ospf1 redistribute=connected,static out-filter-chain=ospf-outFilter rules are evaluated top-to-bottom. Each rule matches on conditions and executes an action. Routes that match no rule are implicitly rejected.
/routing filter rule
# Redistribute loopback and management prefixes as type 1# Type 1: internal OSPF cost + external metric — allows better path selection# across multiple ASBRsadd chain=ospf-out rule="if (protocol connected && dst in 10.10.10.0/24) { \ set ospf-ext-type type1; set ospf-ext-metric 10; accept }"
# Redistribute infrastructure statics as type 2# Type 2: external metric only — simple, lowest metric wins regardless of OSPF pathadd chain=ospf-out rule="if (protocol static && dst in 172.16.0.0/12) { \ set ospf-ext-type type2; set ospf-ext-metric 50; accept }"
# Reject everything else (explicit — redundant but documents intent)add chain=ospf-out rule="reject"Redistributing BGP Routes
Section titled “Redistributing BGP Routes”Redistributing BGP into OSPF injects external prefixes into the OSPF domain. Apply strict prefix-length and prefix-range filters to avoid leaking transit routes or default routes unintentionally.
/routing ospf instanceset ospf1 redistribute=connected,bgp out-filter-chain=ospf-out
/routing filter rule# Accept connected routesadd chain=ospf-out rule="if (protocol connected) { \ set ospf-ext-type type1; set ospf-ext-metric 20; accept }"
# Accept only customer BGP prefixes (/24 and more specific within 192.0.2.0/22)# Do not redistribute transit routes or default routeadd chain=ospf-out rule="if (protocol bgp && dst in 192.0.2.0/22 && dst-len >= 24) { \ set ospf-ext-type type2; set ospf-ext-metric 100; accept }"
add chain=ospf-out rule="reject"Metric Types
Section titled “Metric Types”| Type | Total metric | When to use |
|---|---|---|
type2 (default) | External metric only | Single ASBR or when internal cost to ASBR should not affect route selection |
type1 | Internal cost to ASBR + external metric | Multiple ASBRs advertising the same external prefix; chooses the topologically closer ASBR |
Type 1 metrics are compared as a combined cost, enabling routers to select the ASBR that is topologically closer. Type 2 metrics compare only the external value — all ASBRs advertising the same metric appear equally good until the tie is broken by shortest path to the ASBR.
Default Route Distribution
Section titled “Default Route Distribution”The OSPF instance distribute-default parameter controls whether a default route 0.0.0.0/0 is originated into OSPF.
| Value | Behavior |
|---|---|
never | Do not originate a default route (default) |
if-installed | Originate only when 0.0.0.0/0 exists in the routing table |
always | Always originate regardless of routing table state |
if-installed-as-type1 / always-as-type1 | Same as above but forces type 1 metric |
if-installed-as-type2 / always-as-type2 | Same as above but forces type 2 metric |
# Originate default only when a default route is installed (internet uplink present)/routing ospf instanceset ospf1 distribute-default=if-installed-as-type2
# Always originate default (useful on core routers where OSPF domain has no ABR-generated default)/routing ospf instanceset ospf1 distribute-default=always-as-type2Full Example: Core Router with Multi-Area and Redistribution
Section titled “Full Example: Core Router with Multi-Area and Redistribution”This example shows a single router acting as ABR between backbone (Area 0) and a stub branch (Area 1), while also acting as ASBR by redistributing a connected management prefix and BGP-learned customer routes.
Internet ── [BGP upstream] │ ether1 (10.0.0.1/30) ┌─────────────────────┐ │ core-router │ │ router-id 1.1.1.1 │ └──────┬──────┬───────┘ ether2 ether3 backbone Area 1 (stub) 10.1.0.0/30 10.2.0.0/24# OSPF instance: redistribute connected + BGP, with filter chain/routing ospf instanceadd name=ospf1 version=2 router-id=1.1.1.1 \ redistribute=connected,bgp \ out-filter-chain=ospf-out \ distribute-default=if-installed-as-type2
# Areas/routing ospf areaadd name=backbone area-id=0.0.0.0 instance=ospf1add name=branch1 area-id=0.0.0.1 instance=ospf1 type=stub
# Interface templates/routing ospf interface-template# Backbone: point-to-point to peer routeradd interfaces=ether2 area=backbone network-type=point-to-point# Branch stub area: broadcast LAN, this router is designated as DRadd interfaces=ether3 area=branch1 priority=200# Loopback: passive, advertises management IPadd interfaces=lo0 area=backbone passive=yes
# Route summarization: advertise a single /16 into backbone instead of individual /24s/routing ospf area rangeadd area=branch1 range=10.2.0.0/16 advertise=yes
# Redistribution filter/routing filter rule# Redistribute loopback as type 1add chain=ospf-out rule="if (protocol connected && dst in 10.10.10.0/32) { \ set ospf-ext-type type1; set ospf-ext-metric 10; accept }"# Redistribute BGP customer blocks as type 2add chain=ospf-out rule="if (protocol bgp && dst in 203.0.113.0/24 && dst-len <= 28) { \ set ospf-ext-type type2; set ospf-ext-metric 100; accept }"# Reject all other redistributed routesadd chain=ospf-out rule="reject"Troubleshooting
Section titled “Troubleshooting”Neighbor Stuck Below Full State
Section titled “Neighbor Stuck Below Full State”DR/BDR-related adjacency issues manifest as neighbors stuck at 2-Way (normal for DROther-to-DROther) or ExStart/Exchange (negotiation failure).
# Confirm current DR/BDR on the segment/routing ospf neighbor print detail
# Check priorities match your intent/routing ospf interface-template print detail
# Verify hello and dead intervals match on both routers/routing ospf interface print detailTwo DROther routers on the same segment remain at 2-Way — this is correct OSPF behavior. They form Full adjacency only with the DR and BDR, not with each other.
External Routes Not Appearing After Redistribution
Section titled “External Routes Not Appearing After Redistribution”# Confirm redistribute is set and filter chain is attached/routing ospf instance print detail
# Check what the filter is passing (add a log action temporarily)/routing filter rule print where chain=ospf-out
# Verify external LSAs exist in the LSDB/routing ospf lsa print where type=external
# Confirm routes appear in the routing table on a remote router/ip route print where ospf~"."If external LSAs are present but routes do not appear on remote routers, check that stub areas are not blocking Type 5 LSAs. External routes cannot enter stub areas — use NSSA if local redistribution is required.
Filter Rejecting All Routes
Section titled “Filter Rejecting All Routes”A misconfigured filter chain attached to out-filter-chain silently drops all redistributed routes. Verify the filter chain name matches exactly and that at least one accept rule fires for the routes you expect.
# Remove filter temporarily to confirm redistribution works without it/routing ospf instance set ospf1 out-filter-chain=""
# Check external LSAs appear now/routing ospf lsa print where type=external
# Re-attach filter and narrow down which rule is rejecting/routing ospf instance set ospf1 out-filter-chain=ospf-outRelated Documentation
Section titled “Related Documentation”- OSPF — OSPF fundamentals, LSA types, neighbor states, and authentication
- OSPF Area Types — Stub, totally stubby, and NSSA area configuration with multi-router examples
- Route Filters — Routing filter rule syntax and available matchers and actions
- BGP — BGP configuration for redistributing into OSPF
- BFD — Bidirectional Forwarding Detection for fast link failure detection on OSPF segments