OSPF · Topic 4 of 4

Configure, Monitor and Troubleshoot OSPF

Configure OSPF interfaces in Junos, apply export and import policy, and troubleshoot neighbors with show ospf commands and traceoptions for the JN0-364.

  • 6 min
In a nutshell
  • Enable OSPF with set protocols ospf area <id> interface <name>; use passive on lo0.
  • Defaults: hello 10 s, dead 40 s, priority 128, reference bandwidth 100 Mbps.
  • Export policy injects routes as external type 2 unless then external type 1 is set.

What it is

In Junos, OSPF runs only on the interfaces you list under [edit protocols ospf area <id>]. Each interface also needs family inet with an address.

Routing policy controls which non-OSPF routes are injected into OSPF (export) and which OSPF routes are installed in the routing table (import). Troubleshooting tools are the show ospf commands, clear ospf, and traceoptions, which log OSPF events to a file.

Interfacefamily inetlisted under areaOSPF interfacehellosNeighborFullRoutespreference 10

How it works

Basic interface configuration

user@router# set protocols ospf area 0.0.0.0 interface lo0.0 passive
user@router# set protocols ospf area 0.0.0.0 interface ge-0/0/0.0
user@router# set protocols ospf area 0.0.0.0 interface ge-0/0/1.0 interface-type p2p
user@router# set protocols ospf area 0.0.0.1 interface ge-0/0/2.0

The area can be written as 0 or 0.0.0.0; Junos stores it in dotted form.

Common interface options

OptionEffectDefault
passiveAdvertise the subnet but send no hellos and form no neighborsOff
metric <n>Set the cost by handFrom reference bandwidth
hello-interval, dead-intervalHello timers10 and 40 seconds
priority <n>DR election priority128
interface-type p2pNo DR election on EthernetBroadcast on Ethernet
authentication md5 <key-id> key <key>MD5 authenticationNone
disableStop OSPF on the interface without deleting itOff

The cost is the reference bandwidth divided by the interface bandwidth, with a minimum of 1. The Junos default reference bandwidth is 100 Mbps, so every interface of 100 Mbps or faster gets cost 1. Raise it so faster links get lower costs:

user@router# set protocols ospf reference-bandwidth 100g

Export policy

OSPF does not advertise static, direct (non-OSPF) or BGP routes by default. An export policy makes the router an ASBR and creates type 5 LSAs (type 7 in an NSSA).

user@router# set policy-options policy-statement STATIC-TO-OSPF term 1 from protocol static
user@router# set policy-options policy-statement STATIC-TO-OSPF term 1 from route-filter 10.20.0.0/16 orlonger
user@router# set policy-options policy-statement STATIC-TO-OSPF term 1 then external type 1
user@router# set policy-options policy-statement STATIC-TO-OSPF term 1 then accept
user@router# set protocols ospf export STATIC-TO-OSPF

Without external type 1, the routes are sent as external type 2. The default OSPF export policy rejects everything that is not OSPF, so only routes matched by your policy are added.

Import policy

An OSPF import policy controls which OSPF routes are installed in inet.0. It does not stop LSAs from entering the link-state database or being flooded, because every router in an area must keep the same database.

user@router# set policy-options policy-statement BLOCK-EXT term 1 from route-filter 172.31.0.0/16 orlonger
user@router# set policy-options policy-statement BLOCK-EXT term 1 then reject
user@router# set protocols ospf import BLOCK-EXT
ExportImport
DirectionRouting table into OSPFOSPF into the routing table
DefaultReject non-OSPF routesAccept all
Effect on LSDBCreates external LSAsNone; LSAs are still flooded
Static routeexport policyType 5 LSAfloodedRemote LSDBimport policyRemote inet.0

Monitoring commands

CommandShows
show ospf neighborNeighbors, state, priority, dead timer
show ospf interfaceOSPF interfaces, area, DR and BDR, neighbor count
show ospf interface detailCost, timers, interface type, authentication
show ospf databaseLSAs per area
show route protocol ospfOSPF routes in the routing table
show ospf overviewRouter ID, ABR and ASBR status, area types, SPF timers
show ospf statisticsPacket counters and errors
show ospf logWhen SPF ran and why

Clearing and tracing

clear ospf neighbor resets adjacencies; add an interface or neighbor address to reset only one. Resetting adjacencies interrupts routing, so do it in a maintenance window on a live network.

Traceoptions write OSPF events to a log file in /var/log:

user@router# set protocols ospf traceoptions file ospf-trace size 1m files 3
user@router# set protocols ospf traceoptions flag hello detail
user@router# set protocols ospf traceoptions flag error detail
user@router# commit

user@router> show log ospf-trace
user@router> monitor start ospf-trace

monitor start shows new lines in real time; monitor stop ends it. Remove traceoptions when finished.

A troubleshooting order

No neighborcheckInterface up and family inetcheckInterface listed under areacheckHello parameterstrace hello and errorStuck ExStartcheckMTU on both endsNeighbor Full but no routecheckshow ospf databasecheckImport policy or better route
SymptomLikely cause
No neighbor at allArea ID, timers, area type or authentication mismatch; interface passive; filter blocking protocol 89
Stuck in InitHellos lost in one direction
Stuck in ExStart or ExchangeMTU mismatch
Full, but prefix missing from inet.0Import policy, or another protocol with a lower preference is active
External routes missingExport policy not applied or not matching on the ASBR
Exam tip

traceoptions flag error detail often names the problem directly, for example a hello interval or area mismatch, while show ospf neighbor simply shows no neighbor.

Common mistakes

Making a transit interface passive. A passive interface advertises its subnet but forms no neighbors, so the adjacency never comes up.

Expecting import policy to filter LSAs. It only affects the local routing table. The LSAs still exist in every database in the area.

Forgetting family inet on the interface. Listing the interface under OSPF is not enough without an IPv4 address.

Watch out

An export policy with a final then accept and no from exports every active route, including all BGP routes, into OSPF. Always match the protocol or prefixes you intend.

What to remember for the exam

  • Enable OSPF with set protocols ospf area <id> interface <name>; use passive on lo0.
  • Defaults: hello 10 s, dead 40 s, priority 128, reference bandwidth 100 Mbps.
  • Export policy injects routes as external type 2 unless then external type 1 is set.
  • Default export rejects non-OSPF routes; default import accepts all.
  • Import policy changes only the routing table, not the LSDB.
  • Main tools: show ospf neighbor, interface, database, route, statistics, log, clear ospf neighbor and traceoptions.
  • Traceoptions files are read with show log <file> or monitor start <file>.

Check yourself

  • Which hierarchy applies a policy that injects static routes into OSPF?

    set protocols ospf export <policy>, with a policy that matches from protocol static and accepts.

  • Can an OSPF import policy stop an LSA from being flooded to other routers?

    No; it only controls which OSPF routes are installed in the local routing table.

  • Which traceoptions flags are most useful when no adjacency forms?

    hello and error, which log received hellos and the parameter mismatches that reject them.

Topic 4 of 4 in OSPF

Test yourself on OSPF

The full Juniper JNCIS-SP JN0-364 question bank has 860 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.