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
- Enable OSPF with
set protocols ospf area <id> interface <name>; usepassiveon 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 1is 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.
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
| Option | Effect | Default |
|---|---|---|
passive | Advertise the subnet but send no hellos and form no neighbors | Off |
metric <n> | Set the cost by hand | From reference bandwidth |
hello-interval, dead-interval | Hello timers | 10 and 40 seconds |
priority <n> | DR election priority | 128 |
interface-type p2p | No DR election on Ethernet | Broadcast on Ethernet |
authentication md5 <key-id> key <key> | MD5 authentication | None |
disable | Stop OSPF on the interface without deleting it | Off |
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
| Export | Import | |
|---|---|---|
| Direction | Routing table into OSPF | OSPF into the routing table |
| Default | Reject non-OSPF routes | Accept all |
| Effect on LSDB | Creates external LSAs | None; LSAs are still flooded |
Monitoring commands
| Command | Shows |
|---|---|
show ospf neighbor | Neighbors, state, priority, dead timer |
show ospf interface | OSPF interfaces, area, DR and BDR, neighbor count |
show ospf interface detail | Cost, timers, interface type, authentication |
show ospf database | LSAs per area |
show route protocol ospf | OSPF routes in the routing table |
show ospf overview | Router ID, ABR and ASBR status, area types, SPF timers |
show ospf statistics | Packet counters and errors |
show ospf log | When 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
| Symptom | Likely cause |
|---|---|
| No neighbor at all | Area ID, timers, area type or authentication mismatch; interface passive; filter blocking protocol 89 |
| Stuck in Init | Hellos lost in one direction |
| Stuck in ExStart or Exchange | MTU mismatch |
Full, but prefix missing from inet.0 | Import policy, or another protocol with a lower preference is active |
| External routes missing | Export policy not applied or not matching on the ASBR |
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.
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>; usepassiveon 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 1is 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 neighborandtraceoptions. - Traceoptions files are read with
show log <file>ormonitor start <file>.
Check yourself
Which hierarchy applies a policy that injects static routes into OSPF?
set protocols ospf export <policy>, with a policy that matchesfrom protocol staticand 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?
helloanderror, 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.