In this post, we will look at a basic single-area OSPF configuration.
In Junos, almost all the configuration occurs under the protocols stanza, with no interface-specific changes made under the interface configuration.
This example is relevant to all Junos-based devices – M, T, MX, PTX, SRX, EX, and QFX.
The Quick Answer
The following will give you a basic OSPF configuration. I recommend reading on to get more detail though.
set protocols ospf area 0.0.0.0 interface lo0 passive
set protocols ospf area 0.0.0.0 interface all
set protocols ospf area 0.0.0.0 interface fxp0 disable
set protocols ospf reference-bandwidth 100g
Note: This sets the loopback interface as passive, and then runs OSPF on all other interfaces. It specifically disabled OSPF for the management (fxp0) interface. If your device has a management interface with a different name, you should disable that instead – for example me0, vme0, or em0.
Lab Environment
The lab environment uses logical systems. These are connected together using logical tunnel (lt-) interfaces.

- R1 through R4 are configured using logical systems
- All routers have a loopback interface configured.
- All the interfaces are already configured.
The configuration and show commands listed below are done with the ‘cli logical-system’ set to the relevant logical system. This means commands don’t need to refer to which logical system to run the command against. This makes the output the same as if we were not using logical systems.
Here is an example showing the configuration of R1 before we start.
lab@vRouter-1:R1> show configuration
interfaces {
lt-0/0/0 {
unit 1 {
encapsulation ethernet;
peer-unit 2;
family inet {
address 172.16.12.1/24;
}
}
unit 3 {
encapsulation ethernet;
peer-unit 4;
family inet {
address 172.16.13.1/24;
}
}
}
lo0 {
unit 1 {
family inet {
address 192.168.0.1/32;
}
}
}
}
lab@vRouter-1:R1>
Configuration Choices
Before starting, we need to make a couple of decisions.
- Will we set a router-id manually, or let the router choose for itself?
- Will we set the reference bandwidth to something larger than the default?
OSPF needs to have a Router ID. If we do not set one manually, the router will choose the IP Address of the first interface to come up, which is usually the loopback interface.
For this example, we’ll use both options so you can see both working.
The reference bandwidth is how OSPF calculates the cost of a link. The default of 100Mbps (100000000) is too small for most networks today and causes almost all interfaces to have a cost, or metric, of 1. We’ll be setting the reference bandwidth to 100Gbps.
When choosing the reference bandwidth for your network, select a value likely to remain larger than the largest interface you think you’ll be using in the future.
R1 Configuration
On R1, we’ll configure the Router ID manually.
lab@vRouter-1:R1> edit
Entering configuration mode
[edit]
lab@vRouter-1:R1# set routing-options router-id 192.168.0.1
[edit]
lab@vRouter-1:R1# set protocols ospf reference-bandwidth 100g
[edit]
lab@vRouter-1:R1# set protocols ospf area 0 interface lo0.1 passive
[edit]
lab@vRouter-1:R1# set protocols ospf area 0 interface all
[edit]
lab@vRouter-1:R1# set protocols ospf area 0 interface fxp0 disable
[edit]
lab@vRouter-1:R1# commit and-quit
commit complete
Exiting configuration mode
lab@vRouter-1:R1> show configuration protocols
ospf {
area 0.0.0.0 {
interface lo0.1 {
passive;
}
interface all;
interface fxp0.0 {
disable;
}
}
reference-bandwidth 100g;
}
lab@vRouter-1:R1>
As you can see, on Junos the interfaces are configured under the the OSPF area. The passive statement stops OSPF from trying to establish an adjacency on that interface but includes the interface network as an OSPF internal route.
Using interface all will run OSPF on all interfaces. In this case, all of the interfaces associated with the R1 logical system. The disable statement for fxp0 is to ensure we do not try to run OSPF on the management interface, which would otherwise be included with the interface all statement.
Note: The disable under the fxp0 interface is not disabling the interface as a whole, it is only disabling OSPF on that interface.
We can now do a quick check of the OSPF neighbors and interfaces. We don’t expect any neighbors at this point. Checking the OSPF interfaces helps confirm our configuration is OK.
lab@vRouter-1:R1> show ospf neighbor
lab@vRouter-1:R1> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.1 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.1 DR 0.0.0.0 192.168.0.1 0.0.0.0 0
lt-0/0/0.3 DR 0.0.0.0 192.168.0.1 0.0.0.0 0
lab@vRouter-1:R1>
R2 Configuration
With R2, we will configure OSPF slightly differently. We’ll let the router choose the Router ID, and we won’t use the interface all statement.
lab@vRouter-1:R2> edit
Entering configuration mode
[edit]
lab@vRouter-1:R2# set protocols ospf reference-bandwidth 100g
[edit]
lab@vRouter-1:R2# set protocols ospf area 0 interface lo0.2 passive
[edit]
lab@vRouter-1:R2# set protocols ospf area 0 interface lt-0/0/0.2
[edit]
lab@vRouter-1:R2# set protocols ospf area 0 interface lt-0/0/0.5
[edit]
lab@vRouter-1:R2# show protocols
ospf {
area 0.0.0.0 {
interface lo0.2 {
passive;
}
interface lt-0/0/0.2;
interface lt-0/0/0.5;
}
reference-bandwidth 100g;
}
[edit]
lab@vRouter-1:R2# commit and-quit
commit complete
Exiting configuration mode
lab@vRouter-1:R2>
Since the lt-0/0/0 interface has multiple units, we must specify the unit in the interface statement. If you leave the unit number off, Junos will assume you mean unit 0.
Now we can do a quick check for neighbors and OSPF interfaces.
lab@vRouter-1:R2> show ospf neighbor
Address Interface State ID Pri Dead
172.16.12.1 lt-0/0/0.2 Full 192.168.0.1 128 36
lab@vRouter-1:R2> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.2 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.2 BDR 0.0.0.0 192.168.0.1 192.168.0.2 1
lt-0/0/0.5 DR 0.0.0.0 192.168.0.2 0.0.0.0 0
lab@vRouter-1:R2>
We have a neighbor adjacency with R1, since we configured that earlier.
The lt- interfaces are configured with Ethernet encapsulation which makes them a broadcast interface, which is why we are running DR elections on the interfaces.
R3 And R4 Configuration
The OSPF configuration for R3 and R4 are as follows:
R3:
lab@vRouter-1:R3> show configuration protocols
ospf {
area 0.0.0.0 {
interface lo0.3 {
passive;
}
interface lt-0/0/0.4;
interface lt-0/0/0.7;
}
reference-bandwidth 100g;
}
lab@vRouter-1:R3>
R4:
lab@vRouter-1:R4> show configuration protocols
ospf {
area 0.0.0.0 {
interface lo0.4 {
passive;
}
interface lt-0/0/0.6;
interface lt-0/0/0.8;
}
reference-bandwidth 100g;
}
lab@vRouter-1:R4>
OSPF Verification
Now that we have configured OSPF between the four routers, we can verify OSPF. The following output is taken from R1.
lab@vRouter-1:R1> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.1 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.1 DR 0.0.0.0 192.168.0.1 192.168.0.2 1
lt-0/0/0.3 DR 0.0.0.0 192.168.0.1 192.168.0.3 1
lab@vRouter-1:R1>
We can see R1 is the designated router for both lt- interfaces, the router IDs of the DR and BDR, and the number of neighbors on each interface.
The lo0.1 interface is in the DRother state because we configured it as a passive interface.
lab@vRouter-1:R1> show ospf neighbor
Address Interface State ID Pri Dead
172.16.12.2 lt-0/0/0.1 Full 192.168.0.2 128 36
172.16.13.2 lt-0/0/0.3 Full 192.168.0.3 128 37
lab@vRouter-1:R1>
The show ospf neighbor command shows the state of any adjacencies the router has formed. It shows the address of the peer router, the interface, the priority of the neighbor for DR elections, and the current dead timer.
If you run the command several times in a row, you will see the dead timer changing.
Next, we can look at the OSPF routes in the routing tables.
lab@vRouter-1:R1> show route protocol ospf
inet.0: 11 destinations, 11 routes (11 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.24.0/24 *[OSPF/10] 00:04:25, metric 2
> to 172.16.12.2 via lt-0/0/0.1
172.16.34.0/24 *[OSPF/10] 00:49:13, metric 2
> to 172.16.13.2 via lt-0/0/0.3
192.168.0.2/32 *[OSPF/10] 00:04:25, metric 1
> to 172.16.12.2 via lt-0/0/0.1
192.168.0.3/32 *[OSPF/10] 00:49:13, metric 1
> to 172.16.13.2 via lt-0/0/0.3
192.168.0.4/32 *[OSPF/10] 00:04:25, metric 2
to 172.16.12.2 via lt-0/0/0.1
> to 172.16.13.2 via lt-0/0/0.3
224.0.0.5/32 *[OSPF/10] 05:32:23, metric 1
MultiRecv
inet6.0: 1 destinations, 1 routes (1 active, 0 holddown, 0 hidden)
lab@vRouter-1:R1>
This shows that R1 has a route to the two link-nets between R2 and R4, and between R3 and R4. It also has routes for the loopbacks of the other three routers.
The route towards R4, 192.168.0.4, has two next hops listed. This is because there are two equal paths to R4 from R1. By default, R1 will pick only one of these routes to push into the forwarding table, but we’ll cover that in more detail in another post.
There is another command – show ospf route – which shows routes as OSPF has calculated them, and before they are brought into the main routing table(s). This should not be confused with the show route command we executed before.
lab@vRouter-1:R1> show ospf route
Topology default Route Table:
Prefix Path Route NH Metric NextHop Nexthop
Type Type Type Interface Address/LSP
192.168.0.2 Intra Router IP 1 lt-0/0/0.1 172.16.12.2
192.168.0.3 Intra Router IP 1 lt-0/0/0.3 172.16.13.2
192.168.0.4 Intra Router IP 2 lt-0/0/0.1 172.16.12.2
lt-0/0/0.3 172.16.13.2
172.16.12.0/24 Intra Network IP 1 lt-0/0/0.1
172.16.13.0/24 Intra Network IP 1 lt-0/0/0.3
172.16.24.0/24 Intra Network IP 2 lt-0/0/0.1 172.16.12.2
172.16.34.0/24 Intra Network IP 2 lt-0/0/0.3 172.16.13.2
192.168.0.1/32 Intra Network IP 0 lo0.1
192.168.0.2/32 Intra Network IP 1 lt-0/0/0.1 172.16.12.2
192.168.0.3/32 Intra Network IP 1 lt-0/0/0.3 172.16.13.2
192.168.0.4/32 Intra Network IP 2 lt-0/0/0.1 172.16.12.2
lt-0/0/0.3 172.16.13.2
lab@vRouter-1:R1>
We can show the OSPF database. Here we can see there are four router LSAs and four network LSAs. The database shows only one OSPF area – area 0, as we have no other areas configured. The asterisk ‘*’ next to the router ID shows LSAs generated by the local router.
lab@vRouter-1:R1> show ospf database
OSPF database, Area 0.0.0.0
Type ID Adv Rtr Seq Age Opt Cksum Len
Router *192.168.0.1 192.168.0.1 0x8000000c 867 0x22 0xd8c5 60
Router 192.168.0.2 192.168.0.2 0x8000000a 869 0x22 0xd3b3 60
Router 192.168.0.3 192.168.0.3 0x80000005 873 0x22 0xda97 60
Router 192.168.0.4 192.168.0.4 0x80000004 503 0x22 0xe277 60
Network *172.16.12.1 192.168.0.1 0x80000009 868 0x22 0x4add 32
Network 172.16.13.2 192.168.0.3 0x80000001 873 0x22 0x3feb 32
Network 172.16.24.1 192.168.0.2 0x80000002 507 0x22 0xf32b 32
Network 172.16.34.1 192.168.0.3 0x80000002 512 0x22 0x8989 32
lab@vRouter-1:R1>
We can also look at the ospf statistics and the log of ospf events.
lab@vRouter-1:R1> show ospf statistics
Packet type Total Last 5 seconds
Sent Received Sent Received
Hello 4693 2652 1 1
DbD 12 9 0 0
LSReq 3 2 0 0
LSUpdate 31 23 0 0
LSAck 20 22 0 0
DBDs retransmitted : 0, last 5 seconds : 0
LSAs flooded : 17, last 5 seconds : 0
LSAs flooded high-prio : 24, last 5 seconds : 0
LSAs retransmitted : 1, last 5 seconds : 0
LSAs transmitted to nbr: 4, last 5 seconds : 0
LSAs requested : 3, last 5 seconds : 0
LSAs acknowledged : 26, last 5 seconds : 0
Flood queue depth : 0
Total rexmit entries : 0
db summaries : 0
lsreq entries : 0
Receive errors:
None
lab@vRouter-1:R1> show ospf log
Topology default SPF log:
Last instance of each event type
When Type Elapsed
00:09:02 SPF 0.000261
00:09:02 Stub 0.000013
00:09:02 Interarea 0.000002
00:09:02 External 0.000002
00:09:02 NSSA 0.000001
00:09:02 Cleanup 0.000151
Maximum length of each event type
When Type Elapsed
00:55:29 SPF 0.001503
00:12:01 Stub 0.000243
05:28:16 Interarea 0.000003
00:12:01 External 0.000003
05:39:35 NSSA 0.000002
00:56:25 Cleanup 0.003918
Last 100 events
When Type Elapsed
05:28:09 SPF 0.000041
05:28:09 Stub 0.000023
05:28:09 Interarea 0.000002
05:28:09 External 0.000002
...
<< output removed for brevity>>
...
lab@vRouter-1:R1>
Additional Basic OSPF Configuration
In addition to the basic configuration, there are some additional items you may want to change
- Setting an interface to be a point-to-point interface
- Configuring an interface priority for DR election
- Manually configuring the cost for an interface.
First, let’s change the link between R1 and R3 to a point-to-point link. This will eliminate the need for a DR election. It’s common to set an ethernet interface to be point-to-point where it provides a direct connection between two routers, and no other devices connect to that network.
R1:
lab@vRouter-1:R1> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.1 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.1 DR 0.0.0.0 192.168.0.1 192.168.0.2 1
lt-0/0/0.3 BDR 0.0.0.0 192.168.0.3 192.168.0.1 1
lab@vRouter-1:R1> edit
Entering configuration mode
[edit]
lab@vRouter-1:R1# set protocols ospf area 0 interface lt-0/0/0.3 interface-type p2p
[edit]
lab@vRouter-1:R1# commit and-quit
commit complete
Exiting configuration mode
lab@vRouter-1:R1> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.1 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.1 DR 0.0.0.0 192.168.0.1 192.168.0.2 1
lt-0/0/0.3 PtToPt 0.0.0.0 0.0.0.0 0.0.0.0 0
lab@vRouter-1:R1>
Once we set the interface type to point-to-point, R1 cannot form an adjacency with R3 as the interface types don’t match. Now we’ll quickly update R3.
lab@vRouter-1:R3> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.3 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.4 DR 0.0.0.0 192.168.0.3 0.0.0.0 1
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R3> show ospf neighbor
Address Interface State ID Pri Dead
172.16.13.1 lt-0/0/0.4 Init 192.168.0.1 128 35
172.16.34.2 lt-0/0/0.7 Full 192.168.0.4 128 33
lab@vRouter-1:R3> edit
Entering configuration mode
[edit]
lab@vRouter-1:R3# set protocols ospf area 0 interface lt-0/0/0.4 interface-type p2p
[edit]
lab@vRouter-1:R3# commit and-quit
commit complete
Exiting configuration mode
lab@vRouter-1:R3> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.3 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.4 PtToPt 0.0.0.0 0.0.0.0 0.0.0.0 1
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R3> show ospf neighbor
Address Interface State ID Pri Dead
172.16.13.1 lt-0/0/0.4 Full 192.168.0.1 128 37
172.16.34.2 lt-0/0/0.7 Full 192.168.0.4 128 37
lab@vRouter-1:R3>
As you can see, R3 did think it had a neighbor on the interface, but closer inspection shows it was in the init state. After changing the interface to a point-to-point type the adjacency came up again.
In the next example, we’ll change the R3 to R4 link. We’ll increase the interface priority so R3 will be the designated router, and we’ll increase the interface cost to 15 on both sides.
R3:
lab@vRouter-1:R3> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.3 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.4 PtToPt 0.0.0.0 0.0.0.0 0.0.0.0 1
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R3> show ospf interface lt-0/0/0.7 detail
Interface State Area DR ID BDR ID Nbrs
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
Type: LAN, Address: 172.16.34.1, Mask: 255.255.255.0, MTU: 1500, Cost: 1
DR addr: 172.16.34.2, BDR addr: 172.16.34.1, Priority: 128
Adj count: 1
Hello: 10, Dead: 40, ReXmit: 5, Not Stub
Auth type: None
Protection type: None
Topology default (ID 0) -> Cost: 1
lab@vRouter-1:R3> edit
Entering configuration mode
[edit]
lab@vRouter-1:R3# set protocols ospf area 0 interface lt-0/0/0.7 priority 200 metric 15
[edit]
lab@vRouter-1:R3# commit and-quit
commit complete
Exiting configuration mode
lab@vRouter-1:R3>
lab@vRouter-1:R3> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.3 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.4 PtToPt 0.0.0.0 0.0.0.0 0.0.0.0 1
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R3> show ospf interface lt-0/0/0.7 detail
Interface State Area DR ID BDR ID Nbrs
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
Type: LAN, Address: 172.16.34.1, Mask: 255.255.255.0, MTU: 1500, Cost: 15
DR addr: 172.16.34.2, BDR addr: 172.16.34.1, Priority: 200
Adj count: 1
Hello: 10, Dead: 40, ReXmit: 5, Not Stub
Auth type: None
Protection type: None
Topology default (ID 0) -> Cost: 15
lab@vRouter-1:R3>
Next, we’ll change the cost on R4 for the same link, but leave its priority alone.
lab@vRouter-1:R4> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.4 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.6 BDR 0.0.0.0 192.168.0.2 192.168.0.4 1
lt-0/0/0.8 DR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R4> show ospf interface lt-0/0/0.8 detail
Interface State Area DR ID BDR ID Nbrs
lt-0/0/0.8 DR 0.0.0.0 192.168.0.4 192.168.0.3 1
Type: LAN, Address: 172.16.34.2, Mask: 255.255.255.0, MTU: 1500, Cost: 1
DR addr: 172.16.34.2, BDR addr: 172.16.34.1, Priority: 128
Adj count: 1
Hello: 10, Dead: 40, ReXmit: 5, Not Stub
Auth type: None
Protection type: None
Topology default (ID 0) -> Cost: 1
lab@vRouter-1:R4> edit
Entering configuration mode
[edit]
lab@vRouter-1:R4# set protocols ospf area 0 interface lt-0/0/0.8 metric 15
[edit]
lab@vRouter-1:R4# commit and-quit
commit complete
Exiting configuration mode
lab@vRouter-1:R4> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.4 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.6 BDR 0.0.0.0 192.168.0.2 192.168.0.4 1
lt-0/0/0.8 DR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R4> show ospf interface lt-0/0/0.8 detail
Interface State Area DR ID BDR ID Nbrs
lt-0/0/0.8 DR 0.0.0.0 192.168.0.4 192.168.0.3 1
Type: LAN, Address: 172.16.34.2, Mask: 255.255.255.0, MTU: 1500, Cost: 15
DR addr: 172.16.34.2, BDR addr: 172.16.34.1, Priority: 128
Adj count: 1
Hello: 10, Dead: 40, ReXmit: 5, Not Stub
Auth type: None
Protection type: None
Topology default (ID 0) -> Cost: 15
lab@vRouter-1:R4>
As you can see, the interface cost, or metric, has changed, but R4 is still the DR. In OSPF, the DR is not pre-empted, so it does not automatically change when a higher-priority router is on the network. We need to clear the OSPF adjacency, which we’ll do from R3.
lab@vRouter-1:R3> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.3 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.4 PtToPt 0.0.0.0 0.0.0.0 0.0.0.0 1
lt-0/0/0.7 BDR 0.0.0.0 192.168.0.4 192.168.0.3 1
lab@vRouter-1:R3> clear ospf neighbor interface lt-0/0/0.7
lab@vRouter-1:R3> show ospf interface
Interface State Area DR ID BDR ID Nbrs
lo0.3 DRother 0.0.0.0 0.0.0.0 0.0.0.0 0
lt-0/0/0.4 PtToPt 0.0.0.0 0.0.0.0 0.0.0.0 1
lt-0/0/0.7 DR 0.0.0.0 192.168.0.3 192.168.0.4 1
lab@vRouter-1:R3>
In this case, we cleared the neighbor based on the interface, but if you want to clear all neighbors you can use ‘clear ospf neighbor all’. Be cautious if you are using this on a production network. Ideally, you want to impact the smallest number of OSPF adjacencies as possible.
After clearing the neighbor, R3 is now the DR for the link-net between R3 and R4.
Summary
In this post, we have looked at
- Basic single-area OSPF configuration.
- Setting a reference bandwidth.
- Setting an interface type as point-to-point rather than broadcast.
- Changing interface priority for DR/BDR elections.
- Setting a manual cost for an interface.
You might also like a simple multi-area OSPF configuration on Junos.