In this post, you will learn how to configure Open Shortest Path First (OSPF) version 2 on Cisco IOS. I will show you how to perform basic OSPF configuration, influence SPF calculation and DR/BDR election, set up stub areas, filter LSAs, and more.

Basic OSPF Configuration

First, we will start with basic stuff like enabling OSPF, playing interfaces in areas, configuring cost, OSPF timers, and authentication. Next, I will show you how to implement advanced OSPF features like injecting a default route, filtering LSAs, and so on. So, let’s get started.

Here are the steps to enable OSPF on Cisco IOS:
Step 1. Enable an OSPF process using the router ospf command in global configuration mode (Exhibit 1).

R7> enable 
R7# configure terminal 
R7(config)# router ospf 222

Exhibit 1 – Creating an OSPF process

It is possible to run multiple OSPF instances on a single router, each of which has a separate process ID ranging between 1 and 65535. The process ID is locally meaningful, and has no impact on the OSPF function; therefore, you cannot configure two processes of OSPF on a router using the same identifier. Furthermore, you can implement two OSPF instances on two distinct nodes, and give each a unique identifier.

Upon entering the router ospf command, Cisco IOS determines the router ID using the IPv4 addresses that you have set up in the router. OSPF requires at least one IPv4-enabled interface if you want the OSPF protocol to run properly. Without this, the OSPF instance fails, and Cisco IOS reports the below error.

*May  2 22:46:47.611: %OSPF-4-NORTRID: OSPF process 333 failed to allocate unique router-id and cannot start

Step 2 (optional).

Set a Router ID by typing the router-id command in router configuration mode. This Cisco IOS command expects the router ID number to be provided as an IP address written in decimal format.

To replace the router ID, execute the router-id command, then restart the OSPF process by issuing the clear ip ospf id process command in enable mode, where id represents the ID of the OSPF process to reboot (Exhibit 2).

R6# clear ip ospf 1 process 
Reset OSPF process 1? [no]: yes
*May  2 23:03:22.287: %OSPF-5-ADJCHG: Process 1, Nbr on Serial1/1 from FULL to DOWN, Neighbor Down: Interface down or detached
*May  2 23:03:22.371: %OSPF-5-ADJCHG: Process 1, Nbr on Serial1/1 from LOADING to FULL, Loading Done

Exhibit 2 – Restarting OSPF process 1

Step 3.  Assigning router interfaces to their respective OSPF areas. OSPF can be activated on a specific interface simply by issuing the network or ip ospf area command. After joining an interface to a particular OSPF area, Cisco IOS begins generating Hello packets through that interface in order to establish neighbor adjacencies and describes the interface in the area’s Type 1 LSA.

Understanding The Network Command

Using the network command, you can advertise an interface into an OSPF AS. Here is the syntax of the command:
network ip-address wildcard-mask area area-number,

where ip-address is an IP address formatted in the dotted-decimal style, and wildcard-mask is a 32-bit value that begins with zero or more 0s and finishes with zero or more 1s. Moreover, the wildcard mask must be specified as a decimal IP address. (00000000.00000000.00000000.00000000), (11111111.11111111.11111111.11111111), and (00001111.11111111.11111111.11111111) provide examples of the wildcard mask to be used with the network command.

However, a wildcard mask that has interleaved 0s and 1s, such as (00000010.00000100.00001000.00000000), and (11111111.1.00001101.00011001), are wrong values to be used with the network command (Exhibit 3).

R7(config-router)# network area 0
% OSPF: Invalid address/mask combination (discontiguous mask)

Exhibit 3 – Using invalid wildcard mask

Lastly, area-number is the OSPF area to use with every interface matched by ip-address and wildcard-mask. The IP address range defined by ip-address and wildcard-mask must contain the interface’s IP address for OSPF to be active on it. These are some IP address and wildcard mask combinations you can use with the network command to advertise interface A with IP address into an OSPF area.

IP address Wildcard Mask Description Example
A’s IP address Matches one address, which is A’s IP address network area 12
A’s subnet IP address inverse of A’s subnet mask Covers all IP address in A’s subnet network area 12
A’s major network inverse of A’s major network Covers all IP address in A’s major network network area 12 OSPF will be enabled on all current and future IPv4 interfaces network area 0


In other words, the inverse of an IP address is the address that comes from substituting 0s by 1s, and vice versa, in the initial address. For instance, address begins with twenty-four 1s, next to them eight 0s. Therefore, its inverse begins with 24 0s and ends with eight 1s.

Remember that an interface can be assigned to only one OSPF area regardless of whether several network statements match the IP address of that interface. Hence, in this situation, the most precise network statement, covering fewer IP addresses than the others, wins and the interface gets tied to the OSPF area associated with that network statement.


The easiest method to activate OSPF on a particular interface is to execute the ip ospf area command in interface configuration mode. This Cisco IOS command accepts two arguments: OSPF process ID and area ID (Exhibit 4).

R7(config)# interface loopback 1
R7(config-if)# ip ospf 1 area 2

Exhibit 4 – Enabling OSPF on a loopback interface

In addition, using the ip ospf area command, you can change an interface’s area that was attached to that interface by a network command. However, the contrary is not true, which implies once you set the area of an interface using the ip ospf area statement, you cannot modify it via a network command.

OSPF Network Types

The ip ospf network command enables you to alter the existing network type of an interface (Exhibit 5). When you activate OSPF on a specific interface, Cisco IOS sets the network type of the interface to a value based on the Layer 2 protocol configuration of the interface. For instance, on PPP and HDLC interfaces, the default OSPF network type is Point-to-Point, while it is Broadcast on FastEthernet interfaces.

In addition, the command requires one parameter, and you have only five values to choose from: broadcast, non-broadcast, point-to-multipoint, point-to-multipoint non-broadcast, and point-to-point.

R7(config)# interface serial 1/0
R7(config-if)# ip ospf network broadcast

Exhibit 5 – Setting the network type of the serial 1/0 interface to broadcast

When you select non-broadcast or point-to-multipoint non-broadcast network type, multicast Hello packets are suppressed and the router cannot find OSPF neighbors dynamically. Thus, you have to use the neighbor command in router configuration mode, for every router with which you need to establish OSPF adjacency over the interface.

Loopback Interfaces

The default network type for Loopback interfaces is Loopback (Exhibit 6). OSPF sees a Loopback interface as an isolated node and announces its IP address plus the /32 subnet mask rather than the actual subnet IP address and mask. To alter this behavior, substitute the default network type with the Point-to-Point network type. Moreover, Loopback interfaces don’t allow the four other OSPF network types.

R7# show ip ospf interface loopback 1
Loopback1 is up, line protocol is up 
  Internet Address, Area 2, Attached via Interface Enable
  Process ID 1, Router ID, Network Type LOOPBACK, Cost: 1
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           1         no          no            Base
  Enabled by interface config, including secondary ip addresses
  Loopback interface is treated as a stub Host

Exhibit 6 – displaying Loopback 1’s OSPF settings

Neighbor Command

The neighbor command lets you configure OSPF neighbors explicitly, therefore, instructing the router to build up OSPF adjacencies with your chosen neighbors. You can only use that command on NBMA and Point-to-Multipoint networks. If you try to enter that command on a Point-to-Point or Broadcast interface, Cisco IOS will reject it and display an error message in Exhibit 7.

*May  3 23:18:30.795: %OSPF-4-CFG_NBR_INVALID_NET_TYPE: Can not use configured neighbor on Serial1/0. Neighbor command only allowed on NBMA and P2MP networks

Exhibit 7 – Neighbor command rejected

Hello interval

OSPF uses Hello packets to find neighbors, elect a DR and BDR, and manage OSPF adjacencies. One Hello message gets transmitted every Hello Interval. The Hello Interval is the duration between two successive Hello packets. Also, the default Hello interval value varies based on the OSPF network type of the interface. Below are the default values for the Hello and Dead intervals.

Network Type Hello Interval Dead Interval
Point-to-Point 10 40
Point-to-Multipoint 30 120
Point-to-Multipoint non-broadcast 30 120
Broadcast 10 40
Non-broadcast 30 120


To adjust the hello interval, use the ip ospf hello-interval command in interface configuration mode (Exhibit 8).

R7(config)# interface serial 1/0
R7(config-if)# ip ospf hello-interval 22

Exhibit 8 – Configuring Hello interval

Dead interval

The Dead interval defines the amount of time (in seconds) that must be elapsed before router A marks neighbor B down and deletes it from the neighbor table because A did not receive Hello Packets from B during that duration.

To configure the dead interval, use the ip ospf dead-interval command in interface configuration mode. If you want to set that time interval to a value greater than 1 second, use this syntax:

ip ospf dead-interval seconds

But, if you need to set the dead interval to 1 second, use the following syntax:

ip ospf dead-interval minimal hello-multiplier multiplier, multiplier represents the number of hello packets to send per second.

The following Cisco IOS commands set serial 1/0’s OSPF dead timer to 33:

R7(config)# interface serial 1/0
R7(config-if)# ip ospf dead-interval 33

The following commands set serial 1/0’s OSPF dead and hello intervals to 1s and 50ms, respectively:

R7(config)# interface serial 1/0    
R7(config-if)# ip ospf dead-interval minimal hello-multiplier 20

OSPF reference bandwidth

The OSPF cost of an interface equals (OSPF reference bandwidth) divided by (interface’s bandwidth). Typically, the value of the reference bandwidth is 100Mbps; to adjust it, use the auto-cost reference-bandwidth bw command in router configuration mode, where bw is a value in Mbps between 1 and 4294967 Mbps.

As the default OSPF cost of GigabitEthernet and FastEthernet interfaces is 1, we can modify the OSPF reference bandwidth such that their corresponding OSPF costs correlate with their speeds. To accomplish that, we set the reference bandwidth to 10000 Mbps (Example below). Therefore, the costs of FastEthernet and Gigabit Ethernet links become 100 and 10, respectively.

R7(config)# router ospf 1
R7(config-router)# auto-cost reference-bandwidth 10000

Interface cost

To adjust the cost of an interface, use the ip ospf cost command in interface configuration mode. The next example assigns 100 to the OSPF cost of the serial 1/0 interface.

R7(config)# interface serial 1/0
R7(config-if)# ip ospf cost 100

Note that the cost value you can configure is between 1 and 65535.

OSPF priority

On broadcast and non-broadcast links, routers elect a DR and BDR according to OSPF priority first, then router ID second. The ip ospf priority command, used in interface configuration mode, lets you configure the router priority on a specific network.

You can set a priority value between 0 and 255. Furthermore, a value of 0 means the router cannot become DR or BDR. The subsequent example sets the OSPF priority of interface serial 1/1 to 255.

R7(config)# interface serial 1/1                                 
R7(config-if)# ip ospf priority 255

Advanced OSPF Configuration

OSPF Default routing

If a router’s routing table contains a default external route discovered through a dynamic routing protocol or that was manually added, you can use the default-information originate command in router mode to inject that route into the OSPF domain.

The router constructs one Type 5 LSA for that route, thus the advertising router becomes an ASBR (Exhibit 9). Additionally, you can use the default-information originate always command to inject the route even if no external default route resides in the routing table.

R7# show ip ospf database external self-originate

            OSPF Router with ID ( (Process ID 1)

		Type-5 AS External Link States

  LS age: 45
  Options: (No TOS-capability, DC, Upward)
  LS Type: AS External Link
  Link State ID: (External Network Number )
  Advertising Router:
  LS Seq Number: 80000001
  Checksum: 0x53F6
  Length: 36
  Network Mask: /0
	Metric Type: 2 (Larger than any link state path)
	MTID: 0 
	Metric: 1 
	Forward Address:
	External Route Tag: 1

Exhibit 9 – Type 5 LSA of the default route

This is not the end of this post. Since there is a lot of information to add, this post will get updated on a daily basis until I finish it.

Related Lessons to OSPF Configuration


I hope this blog post helps you learn something.
Now I’d like to turn it over to you:
What did you like about this tutorial?
Or maybe you have an excellent idea that you think I need to add.
Either way, let me know by leaving a comment below right now.

Mohamed Ouamer
Mohamed Ouamer is a computer science teacher and a self-published author. He taught networking technologies and programming for more than fifteen years. While he loves to share knowledge and write, Mohamed's best passions include spending time with his family, visiting his parents, and learning new things.