How to configure OSPF Routing Protocol

OSPF is a routing protocol. This tutorial explains how to configure the OSPF routing protocol on Cisco routers. It uses Packet Tracer network simulator software to explain OSPF configuration steps. You can use any simulator software to practice and learn OSPF configuration. The OSPF configuration steps are the same on all platforms.

OSPF configuration practice involves the following steps.

  • Creating a practice lab and assigning IP configuration to all interfaces
  • Testing connectivity between all interfaces
  • Enabling the OSPF routing on all routers
  • Verifying and testing OSPF configuration

Creating a practice LAB

Add three routers, one PC, and one Server to the workspace. Connect devices and assign IP configuration as shown in the following image.

OSPF configuration packet tracer lab

Download the pre-configured lab with IP configuration.

Testing connectivity

You can use the ping command to test connectivity. A ping command reply verifies devices have connectivity.

Testing connectivity from R1

testing connectivity from R1

Testing connectivity from R2

testing connectivity from R2

Testing connectivity from R3

testing connectivity from R3

OSPF Routing commands

The following two steps in global configuration mode enable OSPF routing on the router.

  1. Enable an OSPF process
  2. Assign area to the interfaces

The following command enables an OSPF process on the router.

Router(config)# router ospf [process_ID]

Process_ID

You can run multiple OSPF processes on a router. The router uses the process_ID to differentiate between OSPF processes. The process_ID is a numeric value. It can be any number from 1 to 65,535. It is locally significant. You do not need to match it on all routers. You can use a different process_ID on each router.

The following command assigns an area to the interface.

Router(config-router)# network IP_network_# [wildcard_mask] area [area number]

Each router interface needs a valid IP address to run. This command matches the given IP address with the IP address of all interfaces. If an interface's IP address matches the given IP address, it enables the OSPF process on that interface and adds that interface to the specified OSPF area.

We use the wildcard mask to match multiple interfaces with a single configuration line. A wildcard mask tells the router the part of the address it should match. It contains wild card bits. In bits, 0 is a matching bit, and 1 is an ignoring bit. For example, the mask 0.255.255.255 indicates a match in the first byte of the network number.

The area-id is the area number we want the interface to be in. The area-id can be an integer between 0 and 4294967295.

OSPF uses areas to limit the routing information routers share. It divides routing information into two types: detailed and summarized. Routers share detailed information only within the same OSPF area. Routers in different OSPF areas share only summarized information. They do not share detailed information. OSPF areas are interface-specific. A router's interfaces can run in separate OSPF areas. Area 0 has a special meaning. OSPF uses it as the backbone area. All OSPF areas must connect with it. It is a compulsory area.

OSPF single-area configuration

OSPF single-area configuration keeps all routers in a single area. Since area 0 is compulsory, a single area OSPF configuration includes only area 0. A multi-area configuration includes more than one OSPF area. In this tutorial, we will configure OSPF in a single area.

Enabling OSPF routing

We will keep all routers in area 0. We will use a different process ID on all routers. Since a process_ID is locally significant, using different process_IDs will not affect OSPF configuration running on other routers. If you want, you can use the same process_ID on all routers. We will enable OSPF routing on all interfaces.

Enabling OSPF Routing on R1

The following commands enable OSPF routing on R1.

Routerr>enable
Router#configure terminal
Router(config)#router ospf 1
Router(config-router)#network 10.0.0.0 0.255.255.255 area 0
Router(config-router)#network 20.0.0.0 0.255.255.255 area 0
Router(config-router)#network 30.0.0.0 0.255.255.255 area 0
Router(config-router)#exit
Router(config)#exit
Router#

enabling ospf on router 1

Enabling OSPF Routing on R2

The following commands enable OSPF routing on R2.

Routerr>enable
Router#configure terminal
Router(config)#router ospf 2
Router(config-router)#network 20.0.0.0 0.255.255.255 area 0
Router(config-router)#network 40.0.0.0 0.255.255.255 area 0
Router(config-router)#exit
Router(config)#exit
Router#

enabling opsf routing on R2

Enabling OSPF Routing on R3

The following commands enable OSPF routing on R3.

Router>enable
Router#configure terminal
Router(config)#router ospf 3
Router(config-router)#network 30.0.0.0 0.255.255.255 area 0
Router(config-router)#network 40.0.0.0 0.255.255.255 area 0
Router(config-router)#network 50.0.0.0 0.255.255.255 area 0
Router(config-router)#exit
Router(config)#exit
Router#

enabling ospf routing on R3

Download Packet Tracer LAB with OSPF Routing

Verifying the OSPF routing

OSPF shares routing information only with neighbors. We use the show ip ospf neighbor command to verify OSPF neighbors. The following image shows the output of this command on R1.

show ospf neigbor

The output includes the following fields.

Neighbor ID

This field displays the RID of the neighbor.

State

This field displays the convergency state. An OSPF router goes through seven states to reach convergency. The Full state in this field verifies the router has reached convergency with the router listed in the neighbor ID field.

Interface

This field displays the local interface connected to the neighbor.

Address

This field displays the IP address of the neighbor.

Dead time

This field displays the dead interval.

The following image shows the output of this command on R2.

show ospf neighbor

The following image shows the output of this command on R3.

show ospf neighbor

Viewing OSPF routes

The show ip route ospf command displays a list of all OSPF routes in the routing table. The following image shows the output of this command on R1.

show ip route ospf

If multiple routes to a destination exist, OSPF adds only the fastest route to the routing table. If two or more routes have an equal cost, it adds all of them to the routing table. It uses them to load balance. For example, R2 has two equal-cost routes for the network 30.0.0.0/8. It adds both routes to the routing table.

show ip route ospf

The following image shows the output of the show ip route ospf command on R3.

show ip route ospf

Testing connectivity between end devices

We can test connectivity between end devices to verify the OSPF configuration on all routers. Send ping requests from PC to Server. If it gets replies, it verifies the OSPF configuration. We can also use the tracert command to print the path the data packets take to reach the destination.

testing ospf routing

R1 is the default gateway for PC. It has two routes to reach the network 50.0.0.0/8: direct route and via R2. It forwards data packets through the second route. The first route has a serial and an Ethernet link. The second route has three Ethernet links. A serial link with default bandwidth costs 64. A 100 Mbps Ethernet link with default bandwidth costs 1. The total cost of the first route is 3 (1+1+1). The total cost of the second route is 65 (64+1). OSPF selects the route that has the least cost.

ComputerNetworkingNotes CCNA Study Guide How to configure OSPF Routing Protocol