OSPF Overview

Open Shortest Path First (OSPF) is a link-state routing protocol that is designed to work with large, more complex networks. OSPF is a classless routing protocol that supports VLSM and CIDR, and uses the Shortest Path First (SPF) algorithm to calculate the best path to a network. OSPF uses a routing metric of “cost” that in Cisco’s implementation is based mainly on the bandwidth of a link. OSPF is able to support hierarchical and scalable network designs through its ability to handle multiple OSPF routing areas.

The Cisco CCNA curriculum requires students to know how to implement and configure only a single-area OSPF network.

OSPF has some similarities to EIGRP, especially in regards to configuration, like requiring a process-id number, using wildcard bits for the subnet mask, hello packets, neighbor relationships or adjacencies, triggered updates, and the use of multiple tables like the neighbor and topology tables.

OSPF Characteristics

  • Algorithm – Dijsktra’s SPF algorithm
  • Metric – Cost, which is based on the bandwidth of a link
  • Administrative Distance – 110
  • Process-ID number – the process-id number is declared when OSPF is started/configured and is a number from 1 to 65535. The process id number does NOT need to match other OSPF routers in the area in order to create adjacencies (see commands below).
  • Wildcard bits/mask – The wildcard mask is the inverse of a network subnet mask (e.g. is It is declared after the network number in the network command (see commands below)
  • Area number – The area number is a number from 0-255, declared at the end of the network command after the wildcard bits. Routers in the same area will exchange routing information or Link State Updates or LSUs (see commands below)
  • Hello Interval – Hello packets are sent every 10 seconds by default. In order for OSPF routers to establish neighbor adjacencies and exchange routing information successfully, the hello interval needs to match all OSPF routers in the OSPF area.
  • Dead Interval – The dead interval is 40 seconds by default. The dead interval should be 4 times the hello interval, and needs to match all OSPF routers in the area
  • Multiple Tables – Routing Table, Topology Table, and Neighbor Adjacency Table
  • DR and BDR Elections – In broadcast multi-access networks (Ethernet), routers in the OSPF area will elect a Designated Router (DR) and a Backup Designated Router (BDR). The DR will be the receiver and distributor of Link-State Packets to other routers in the OSPF area. The BDR will wait, and be ready to take over the duties of the DR in case it fails.

IOS CLI Commands

The router ospf command starts the OSPF routing process. The process ID number can be a number between 1 and 65535:

 router(config)# router ospf <process-id>

  EXAMPLE: router(config)# router ospf 1

The network command will add a connected network to the routing process. In addition to the network IP address you need to provide the wildcard mask, which is the inverse of the subnet mask and the area parameter and number. Typically in single area OSPF the area is often set to area 0.

 router(config-router)# network <network-number> <wildcard-mask> area <area-number>

  EXAMPLE: router(config-router)# network area 0
EXAMPLE: router(config-router)# network area 0
  EXAMPLE: router(config-router)# network area 0 //for a /30 subnet mask

In OSPF, the router-id command will manually set the router’s router-id. In broadcast multi-access networks the router with the highest router-ID will become the designated router (DR) and the router with the second highest router-ID will become the backup designated router (BDR).

 router(config-router)# router-id <ip-address>

  EXAMPLE: router(config-router)# router-id

The passive-interface command can be used to stop OSPF packets from being sent out of a network interface where there are no other OSPF routers present.

 router(config-router)# passive-interface <interface-number>

  EXAMPLE: router(config-router)# passive-interface fastEthernet 0/0

Cisco’s OSPF cost metrics do not account for links faster than 100 Mbps. For example, a 100 Mbps Ethernet interface will calculate to an OSPF cost of 1, but what if you have a 1000 or 10000 Mbps Ethernet interface? The auto-cost reference-bandwidth can adjust the cost metrics to account for links fast than 100 Mbps.

 router(config-router)# auto-cost reference-bandwidth <megabits-per-second>

  EXAMPLE: router(config-router)# auto-cost reference-bandwidth 10000


The default-information originate command will distribute a default route to other OSPF area routers.

 router(config-router)# default-information originate 

You can use either of the following commands to exit out of router configuration mode.

 router(config-router)# end
router(config-router)# exit

Since OSPF relies on bandwidth for the metric, it is a good idea to set the specific bandwidth of the serial interface, otherwise the Cisco serial interfaces will default to a speed of 1544 Kbps, which may lead to an inaccurate measurement of the cost of the link. It is important to remember that this command is applied to the network interface in interface configuration mode.

 router(config)# interface serial <interface-number>
router(config-if)# bandwidth <speed-in-kbps>

  EXAMPLE: router(config)# interface serial 0/0/0
router(config-if)# bandwidth 384

Another command that is applied to a network interface is the ip ospf priority command. This command can be used to manipulate the DR/BDR election process. By default, the Cisco router’s interfaces are all given an OSPF priority of 1, by changing this value to a higher number you can effect the DR/BDR elections. An OSPF priority of 0 will insure the router is never the DR, but an OSPF priority number of 255 will insure that the router will be elected as the designated router or DR.

 router(config-if)# ip ospf priority <0-255>

  EXAMPLE: router(config-if)# ip ospf priority 255

The following commands are all applied to a network interface, but they all effect the OSPF routing protocol operation. Instead of configuring the bandwidth of the link, which will subsequently effect the calculation of the cost metric, you can configure the cost value directly. To do this you need to know how to manually calculate the cost metric. The cost metric of a network link is calculated by the following method: cost equals 10^8 power divided by the network interface speed in bits per second, e.g. the cost for Fast Ethernet is 10^8/100,000,000 = 1..

 router(config-if)# ip ospf cost <cost-value>

  EXAMPLE: router(config-if)# ip ospf cost 781 //for a 128kbps link

For neighboring OSPF routers to achieve adjacencies the OSPF hello interval and dead interval, on each OSPF router needs to match. In a multi-access, broadcast network the default hello interval is 10 seconds, and the dead interval is set to four times the hello interval, or 40 seconds. You can manipulate these times to, for example: have less hello packets on the network, but if you adjust the hello interval, you also need to adjust the dead interval, and you need to do so, for all OSPF routers in the OSPF area.

 router(config-if)# ip ospf hello-interval <seconds>
router(config-if)# ip ospf dead-interval <seconds>

  EXAMPLE: router(config-if)# ip ospf hello-interval 10
router(config-if)# ip ospf dead-interval 40


The following show commands are useful in verifying and troubleshooting OSPF operation and configuration, as well as identifying the router-ids and the identities of the DR and BDR. 

 router# show ip ospf neighbor
router# show ip ospf interface
router# clear ip ospf process
router# show running-config
router# show ip protocols
router# show ip route

Sample Command Usage

router(config)#router ospf 1
router(config-router)#network area 0
router(config-router)#network area 0
router(config-router)#passive-interface fa0/1
router(config-router)#default-information originate
router#show ip ospf neighbor
router# show ip ospf interface
router# clear ip ospf process

OSPF Show Commands

Example OSPF Network

     router#show ip ospf neighbor

In the “show ip ospf neighbor” command above you can see that the router R0 has established three neighbor relationships or adjacencies with the other routers. The “Neighbor ID” above is the neighbor router’s Router ID#. The Router ID# can be different than the neighbor router’s IP address on the network. In the example above the first router listed has a Router or Neighbor ID of but its IP address on the network is You can also see that router at (R3) is the current BDR or Backup Designated router and that the “Pri” or Router Priority Number has been changed from the default number of 1 to 50. The “State” shows that all three routers have current “FULL” adjacency or neighbor relationships. DROTHER routers will only form FULL adjacencies with DR and BDR routers and 2WAY adjacencies with each other. You can see this in the image of R1’s “show ip ospf neighbor” output above. Even if we only look at the output of R0’s show command above (top router output image) we can infer that the Designated Router or DR must be the router that issued the command (R0), because of the fact that there is no neighbor listed as a DR, only a BDR and two DROTHERs.

     router#show ip route

In the image above, the “show ip route” command has been issued, displaying router R0’s routing table. From the routing table we can tell that the R0 router has two connected networks “c on FastEthernet0/1” and “c on FastEthernet0/0” and that it has learned from OSPF about routes to three additional “o” networks:,, and a “o*E2” candidate default route/gateway of last resort.

Author: Dan

Dan teaches computer networking and security classes at Central Oregon Community College.

Leave a Reply

Your email address will not be published.