Cisco OSPF Configuration Guide – Open Shortest Path First

By | April 2, 2014

SPT introducing OSPF configuration tutorial as part of Cisco Networking Tutorials. There are 2 kind classes in routing protocol viz. Distance vector Protocol and Link state protocol. OSPF stands for Open Shortest Path First and belongs to Link-State routing protocol. Cisco OSPF routing protocol is categorized as best dynamic protocols that be present nowadays. It is also regarded as the advanced routing protocol that targets to maintain loop-free and precise routing tables. The important key feature of OSPF is that it is an open source routing protocol. It will run on most routers, since it is an open standard. In my last article we discussed about EIGRP configuration guide. This is the next step of Cisco networking about Cisco OSPF configuration and troubleshooting. Here I explained Cisco OSPF basic configuration with example of Packet Tracer.

Cisco OSPF Configuration Guide

What is OSPF (Open Shortest Path First)?

  • OSPF stands for Open Shortest Path First. OSPF uses SPF algorithm which is developed by Dijkstra, to deliver a loop-free topology.

Dijkstra

(Edsger Wybe Dijkstra: Read More)

[Image credit: http://www.thocp.net]

  • OSPF is an open source Link state routing protocol hence capable of running all network routers.
  • It supports VLSM (variable Length Subnet Mask).
  • Uses COST as a metric which CISCO explain as the inverse of the bandwidth.

OSPF Metric Calculation

  • To allow measurability OSPF bears two important theories: Autonomous systems (Discussed in previous article) and Areas.
  • What is OSPF area? OSPF network can be separated into sub-domains known as areas. An area is a logical group of OSPF networks, routers, and links that have the same area identification number.
  • A router belong to an area should keep a topological database for the area. The router does not have enough information about network configuration external of its area, in that way reducing the size of OSPF database.

OSPF Area
[Image credit: http://www.technet.microsoft.com]

  • The default or else central area is Area 0 (Zero) and all other areas directly connected to it.
  • Within an area OSPF router exchange LSAs (Link State Advertisements) by which routers forms adjacency. (Time being remember LSA means routing information, I will be posting different kinds of LSAs in later, Keep in touch)

How OSPF Works?

By comparing to other Routing Protocol OSPF is little bit complex and hassle. But if you have the complete idea about OSPF working, it is easy to configure and Tshoot.

Now we’ll go over the process of working of an OSPF protocol. While dealing with OSPF there are two important terms; Designated Router (DR) and Backup Designated Router (BDR).

What is Designated Router in OSPF?

Exchanging LSA between all routers significantly increase the traffic and reduce the response time. In an OSPF network instead of broadcasting LSA between to all routers each other, the network selects a router as Designated Router just like a master router.

All other routers exchange routing information to the elected router (Designated Router) only. Then Designated Router broadcasts routing information to all other routers residing at same area thereby reducing the traffic. DR serves as the central point for exchanging OSPF routing information.

What is Backup Designated Router (BDR)?

In any case DR fails BDR coming in to action. Backup Designated Router works as a stand by router for OSPF information.

When Designated Router fails, Backup Designated Router (BDR) takes over its role of spreading routing information across the OSPF area.

DR-BDR Election in OSFP Area

  • The selection process of Designated Router (DR) and Backup Designated Router (BDR) occurs at the beginning of OSPF network established.
  • Each router in an OSPF network allotted with number called Router Identifier Number (router-id). OSPF uses this to identify DR-BDR. (Routerid can be assigned by different methods)
  • Once the OSPF links are active router with maximum router-id (highest loopback IP) elected as DR and the router with second highest router-id chosen as BDR.
  • What happens if the designated router fails or drops connectivity, the backup designated router turns to Designated Router and a new BDR election carried out in the OSPF domain.
  • Process of electing DR and BDR called DR-BDR election in OSPF network.

Now I’m going to go to OSPF configuration commands.

How to Configure OSPF in Cisco router?

OSPF Configuration syntax as follows

Router(config)#router ospf <OSPF Process number>
Router(config-router)#network <Network ID> <Wild Card Mask> area <Area number>

OSPF Process number: Is just a number local to the router only. This value does not ensure be the same on all router within the area. Though, it is better to keep this as same for all routers inside an area for better administration.

Network ID: Is the directly connected network address.

Wildcard mask: Is the inverse of Subnet mask

Area number : Logical group of OSPF network.

Cisco Packet Tracer OSPF Configuration Example

Let’s consider the following Packet Tracer scenario for Cisco OSPF configuration examples.
Cisco OSPF configuration  example
Basic Cisco OSPF configuration commands are follows, Cisco OSPF wildcard mask is used here. If you are new to wildcard mask checkout this Cisco OSPF wildcard mask calculator tool.

(The IP assigning configuration steps are not given in here, assign IP to each interfaces as shown in above scenario.)

Router 1

Cisco OSPF configuration  Router 1
OSPF configuration using packet tracer in Router 1

R1>enable
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#router ospf 1
R1(config-router)#network 10.0.0.0 0.255.255.255 area 0
R1(config-router)#network 20.0.0.0 0.255.255.255 area 0
R1(config-router)#exit
R1(config)#
R1#
%SYS-5-CONFIG_I: Configured from console by console

R1#

Router 2

Cisco OSPF configuration  Router 2
Cisco OSPF network command for Router 2

R2>enable
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#router ospf 1
R2(config-router)#network 10.0.0.0 0.255.255.255 area 0
R2(config-router)#network 30.0.0.0 0.255.255.255 area 0
R2(config-router)#exit
R2(config)#
R2#
%SYS-5-CONFIG_I: Configured from console by console

R2#

Router 3

Cisco OSPF configuration  Router 3
OSPF configuration examples packet tracer for Router 3

R3>enable
R3#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#router ospf 1
R3(config-router)#network 10.0.0.0 0.255.255.255 area 0
R3(config-router)#network 40.0.0.0 0.255.255.255 area 0
R3(config-router)#exit
R3(config)#
R3#
%SYS-5-CONFIG_I: Configured from console by console

R3#

Router 4

Cisco OSPF configuration  Router 4
Router 4 OSPF configuration in packet tracer

R3>enable
R3#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R4(config)#router ospf 1
R4(config-router)#network 10.0.0.0 0.255.255.255 area 0
R4(config-router)#network 50.0.0.0 0.255.255.255 area 0
R4(config-router)#exit
R4(config)#
R4#
%SYS-5-CONFIG_I: Configured from console by console

R4#

In the above example Router 4 elected as DR, because its fast Ethernet interface having IP address 50.0.0.1 which is greater than any other IP in the OSPF domain.

The second highest IP goes to Router 3; of course Router 3 is the BDR.

OSPF Configuration commands are completed. Do as many Cisco OSPF lab exercises that you can to get familiar with configuration. Now there are some OSPF verification commands.

OSPF Verification and Testing Commands

A network admin must know these commands to properly manage the topology.

#show ip ospf

List OSPF status

R1#show ip ospf
Routing Process "ospf 1" with ID 20.0.0.1
Supports only single TOS(TOS0) routes
Supports opaque LSA
SPF schedule delay 5 secs, Hold time between two SPFs 10 secs
Minimum LSA interval 5 secs. Minimum LSA arrival 1 secs
Number of external LSA 0. Checksum Sum 0x000000
Number of opaque AS LSA 0. Checksum Sum 0x000000
Number of DCbitless external and opaque AS LSA 0
Number of DoNotAge external and opaque AS LSA 0
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
External flood list length 0
Area BACKBONE(0)
Number of interfaces in this area is 2
Area has no authentication
SPF algorithm executed 3 times
Area ranges are
Number of LSA 5. Checksum Sum 0x02f34a
Number of opaque link LSA 0. Checksum Sum 0x000000
Number of DCbitless LSA 0
Number of indication LSA 0
Number of DoNotAge LSA 0
Flood list length 0

#show ip ospf interface

Displays OSPF information associated with all available interfaces.

R1#show ip ospf interface
FastEthernet0/1 is up, line protocol is up
Internet address is 20.0.0.1/8, Area 0
Process ID 1, Router ID 20.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 20.0.0.1, Interface address 20.0.0.1
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:00
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 0, Adjacent neighbor count is 0
Suppress hello for 0 neighbor(s)
FastEthernet0/0 is up, line protocol is up
Internet address is 10.0.0.1/8, Area 0
Process ID 1, Router ID 20.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DROTHER, Priority 1
Designated Router (ID) 50.0.0.1, Interface address 10.0.0.4
Backup Designated Router (ID) 40.0.0.1, Interface address 10.0.0.3
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:00
Index 2/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 3, Adjacent neighbor count is 2
Adjacent with neighbor 50.0.0.1 (Designated Router)
Adjacent with neighbor 40.0.0.1 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
R1#

#show ip ospf interface <interface name>

To show OSPF information associated a specific interface

R1#show ip ospf interface fastEthernet 0/0
FastEthernet0/0 is up, line protocol is up
Internet address is 10.0.0.1/8, Area 0
Process ID 1, Router ID 20.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DROTHER, Priority 1
Designated Router (ID) 50.0.0.1, Interface address 10.0.0.4
Backup Designated Router (ID) 40.0.0.1, Interface address 10.0.0.3
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:02
Index 2/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 3, Adjacent neighbor count is 2
Adjacent with neighbor 50.0.0.1 (Designated Router)
Adjacent with neighbor 40.0.0.1 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
R1#

#debug ip ospf events

Displays OPSF events

R1#debug ip ospf events
OSPF events debugging is on
R1#
00:08:20: OSPF: Rcv hello from 40.0.0.1 area 0 from FastEthernet0/0 10.0.0.3

00:08:20: OSPF: End of hello processing

00:08:20: OSPF: Rcv hello from 50.0.0.1 area 0 from FastEthernet0/0 10.0.0.4

00:08:20: OSPF: End of hello processing

00:08:20: OSPF: Rcv hello from 30.0.0.1 area 0 from FastEthernet0/0 10.0.0.2

00:08:20: OSPF: End of hello processing

R1#

#show ip ospf neighbor

Shows OSPF neighbor network and its state (DR-BDR)

R1#show ip ospf neighbor

Neighbor ID Pri State Dead Time Address Interface
40.0.0.1 1 FULL/BDR 00:00:30 10.0.0.3 FastEthernet0/0
50.0.0.1 1 FULL/DR 00:00:30 10.0.0.4 FastEthernet0/0
30.0.0.1 1 2WAY/DROTHER 00:00:30 10.0.0.2 FastEthernet0/0
R1#

#show ip ospf neighbor detail

View all OSPF neighbor details

R1#show ip ospf neighbor detail
Neighbor 40.0.0.1, interface address 10.0.0.3
In the area 0 via interface FastEthernet0/0
Neighbor priority is 1, State is FULL, 7 state changes
DR is 10.0.0.4 BDR is 10.0.0.3
Options is 0x00
Dead timer due in 00:00:39
Neighbor is up for 00:13:50
Index 1/1, retransmission queue length 0, number of retransmission 0
First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
Last retransmission scan length is 0, maximum is 0
Last retransmission scan time is 0 msec, maximum is 0 msec
Neighbor 50.0.0.1, interface address 10.0.0.4
In the area 0 via interface FastEthernet0/0
Neighbor priority is 1, State is FULL, 5 state changes
DR is 10.0.0.4 BDR is 10.0.0.3
Options is 0x00
Dead timer due in 00:00:39
Neighbor is up for 00:13:50
Index 2/2, retransmission queue length 0, number of retransmission 0
First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
Last retransmission scan length is 0, maximum is 0
Last retransmission scan time is 0 msec, maximum is 0 msec
Neighbor 30.0.0.1, interface address 10.0.0.2
In the area 0 via interface FastEthernet0/0
Neighbor priority is 1, State is 2WAY, 8 state changes
DR is 10.0.0.4 BDR is 10.0.0.3
Options is 0x00
Dead timer due in 00:00:39
Neighbor is up for 00:13:50
Index 3/3, retransmission queue length 0, number of retransmission 0
First 0x0(0)/0x0(0) Next 0x0(0)/0x0(0)
Last retransmission scan length is 0, maximum is 0
Last retransmission scan time is 0 msec, maximum is 0 msec
R1#

#clear ip ospf process

Resets full OSPF process, pushing OSPF to rebuild neighbors, database, and routing table

R1#clear ip ospf process
Reset ALL OSPF processes? [no]: no

R1#clear ip ospf process
Reset ALL OSPF processes? [no]: yes

00:17:16: %OSPF-5-ADJCHG: Process 1, Nbr 40.0.0.1 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset

00:17:16: %OSPF-5-ADJCHG: Process 1, Nbr 50.0.0.1 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Adjacency forced to reset

00:17:16: %OSPF-5-ADJCHG: Process 1, Nbr 30.0.0.1 on FastEthernet0/0 from 2WAY to DOWN, Neighbor Down: Adjacency forced to reset

00:17:16: %OSPF-5-ADJCHG: Process 1, Nbr 40.0.0.1 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached

00:17:16: %OSPF-5-ADJCHG: Process 1, Nbr 50.0.0.1 on FastEthernet0/0 from FULL to DOWN, Neighbor Down: Interface down or detached

00:17:16: %OSPF-5-ADJCHG: Process 1, Nbr 30.0.0.1 on FastEthernet0/0 from 2WAY to DOWN, Neighbor Down: Interface down or detached

R1#
00:17:20: %OSPF-5-ADJCHG: Process 1, Nbr 50.0.0.1 on FastEthernet0/0 from LOADING to FULL, Loading Done

00:17:20: %OSPF-5-ADJCHG: Process 1, Nbr 40.0.0.1 on FastEthernet0/0 from LOADING to FULL, Loading Done

R1#

#show ip ospf database

Displays OSPF database

R1#show ip ospf database
OSPF Router with ID (20.0.0.1) (Process ID 1)

Router Link States (Area 0)

Link ID ADV Router Age Seq# Checksum Link count
20.0.0.1 20.0.0.1 404 0x80000004 0x0042a7 2
50.0.0.1 50.0.0.1 404 0x80000004 0x00e1aa 2
40.0.0.1 40.0.0.1 399 0x80000004 0x00f1b9 2
30.0.0.1 30.0.0.1 399 0x80000004 0x0002c8 2

Net Link States (Area 0)
Link ID ADV Router Age Seq# Checksum
10.0.0.4 50.0.0.1 399 0x80000003 0x00da78
R1#

#show ip protocols

To know which routing protocol is enabled in specific router

R1#show ip protocols

Routing Protocol is "ospf 1"
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Router ID 20.0.0.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
20.0.0.0 0.255.255.255 area 0
10.0.0.0 0.255.255.255 area 0
Routing Information Sources:
Gateway Distance Last Update
20.0.0.1 110 00:10:20
30.0.0.1 110 00:10:20
40.0.0.1 110 00:10:20
50.0.0.1 110 00:10:20
Distance: (default is 110)

R1#

#show ip route

Shows the routing table of router

R1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
* - candidate default, U - per-user static route, o - ODR
P - periodic downloaded static route

Gateway of last resort is not set

C 10.0.0.0/8 is directly connected, FastEthernet0/0
C 20.0.0.0/8 is directly connected, FastEthernet0/1
O 30.0.0.0/8 [110/2] via 10.0.0.2, 00:11:15, FastEthernet0/0
O 40.0.0.0/8 [110/2] via 10.0.0.3, 00:11:15, FastEthernet0/0
O 50.0.0.0/8 [110/2] via 10.0.0.4, 00:11:15, FastEthernet0/0
R1#

How to Set Priority for a Router Becomes DR-BDR?

  • Network Administrator can manually assign priority for routers belong to an area by using OSPF priority VALUE  configuration command [Router(config-if)#ip ospf priority priority-value]
  • By default, routers allotted a priority of 128.
  • By configuring a priority 0 results the router as ineligible to become the designated router.
  • Priority value 255 makes a router always be the designated router.

In the above example Router 4 is DR and Router 3 is BDR. I’m gonna to change manually the DR to Router 1 and BDR to Router 2.
Enter the following commands in Router 1

R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#interface fastEthernet 0/0
R1(config-if)#ip ospf priority 255
R1(config-if)#exit

Now enter the following commands in Router 2

R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#interface fastEthernet 0/0
R2(config-if)#ip ospf priority 254
R2(config-if)#exit

To enable these changes you should restart the OSPF process by entering #clear ip ospf process command.

Now let’s verify whether the DR-BDR changed or not by entering #show ip ospf interface in Router 1.

R1#show ip ospf interface
FastEthernet0/1 is up, line protocol is up
Internet address is 20.0.0.1/8, Area 0
Process ID 1, Router ID 20.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 20.0.0.1, Interface address 20.0.0.1
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:05
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 0, Adjacent neighbor count is 0
Suppress hello for 0 neighbor(s)
FastEthernet0/0 is up, line protocol is up
Internet address is 10.0.0.1/8, Area 0
Process ID 1, Router ID 20.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 254
Designated Router (ID) 20.0.0.1, Interface address 10.0.0.1
Backup Designated Router (ID) 30.0.0.1, Interface address 10.0.0.2
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:05
--More--

Yes, now the state of Router 1 changed to DR.

For Router 2 enter#show ip ospf interface

R2#show ip ospf interface
FastEthernet0/0 is up, line protocol is up
Internet address is 10.0.0.2/8, Area 0
Process ID 1, Router ID 30.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State BDR, Priority 253
Designated Router (ID) 20.0.0.1, Interface address 10.0.0.1
Backup Designated Router (ID) 30.0.0.1, Interface address 10.0.0.2
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:03
Index 1/1, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 1
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 3, Adjacent neighbor count is 3
Adjacent with neighbor 20.0.0.1 (Designated Router)
Adjacent with neighbor 50.0.0.1
Adjacent with neighbor 40.0.0.1
Suppress hello for 0 neighbor(s)
FastEthernet0/1 is up, line protocol is up
Internet address is 30.0.0.1/8, Area 0
Process ID 1, Router ID 30.0.0.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 30.0.0.1, Interface address 30.0.0.1
--More--

We can see that Router 2 state is BDR. Apart from assigningIP OSPF priority number you may configure a loopback interface having highest IP will also give priority for BR-BDR.

How to Remove OSPF Configuration?

How to remove OSPF configurations settings from a router? Router(config)#no router ospf <number> command do that job

R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no router ospf 1
R1(config)#exit

%SYS-5-CONFIG_I: Configured from console by console
R1#

As I stated at the earlier, OSPF routing protocol is the best dynamic protocols exist today. It takes all the essential features of an interior gateway routing protocol.

Hope this Cisco OSPF guide and Cisco OSPF lab added some networking skills to your knowledge. Let me know your feedback and comments.

In my next article I will be coming with Redistribution between Multiple Routing Protocols that is how to route between different routing protocols.

Meanwhile like our Facebook page to get latest updates.

One thought on “Cisco OSPF Configuration Guide – Open Shortest Path First

  1. Winnie andrias

    I am responsible for planning and deploying IP networks in the company that I work for and my practical experience was low. However, this tutorial has increased my level of practical experience. This tutorial explains the basic knowledge and skills required to configure and trouble shoot ospf configuration. The skills learned will assist me to do ccna program. Thanks for hosting and sharing osfp on internet.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *