Cisco OSPF Basic Configuration

Cisco OSPF Basic Configuration

In this Cisco CCNA tutorial, you’ll learn how to do a basic configuration of OSPF on our Cisco routers. Scroll down for the video and also text tutorials.

Cisco OSPF Basic Configuration Video Tutorial

YouTube video

Will Clifton

Will Clifton

This course “filled in the blanks” left by textbooks and other videos. Neil communicates concepts and real-world scenarios extremely well. I have found it to be a good match for my pacing and a valuable tool either on its own or in tandem with other study materials.

Will Clifton

OSPF Configuration – Process ID

 

To enable OSPF, the top-level command at global config is 'router ospf' and then a Process ID. As you can see in the example below, I've said 'router ospf 1'.

 

Cisco OSPF Basic Configuration

 

Different interfaces on a router can run in different instances or different Process IDs of OSPF. Different instances have different LinkState Databases (LSDB) running separately. Only one instance is typically configured on OSPF routers. Multiple Process IDs are very rarely used.

 

It's not normal to have different Process IDs on the router. The Process ID is locally significant, so it does not have to match the neighbor router for them to form an adjacency.

 

In the example below, we've got 3 routers, R1, R2, and R3, with R2 in the middle. On R3, both interfaces have been put in Process ID 1. On R2, the left-hand interface is in Process ID 2, the right-hand interface is in Process ID 3, and on R1, its left-hand interface is in Process ID 4.

 

OSPF Configuration - Process ID

 

R2 will form adjacencies both with R3 and with R1. So even though the Process ID is different on the routers, that's a locally significant number. It does not have to match on both sides, so the routers will still form adjacencies.

 

In our example, on R2, the left-hand and the right-hand interfaces are in two different processes. So they're going to have separate Link State Databases, and information will not be shared between the two sides. R1 and R3 will not learn routes to each other because both sides are in different process IDs on router R2.

 

The way we would configure this is on R2, we say 'router ospf 2' at global config, and then 'network 10.0.0.0', the wildcard mask, '0.0.0.255 area 0', and then for the other interface, we say 'router ospf 3' and ‘network 10.1.0.0 0.0.0.255 area 0’.

 

That's how you can have different processes for OSPF running on the same router. It is absolutely not normal to do that.

 

OSPF Configuration - Process ID routes

 

What is more normal is that all the routers in your network are all using the same Process ID number. So you can see now that on routers R1, R2, and R3, using the same topology as before, we've configured OSPF Process ID 1 on all interfaces.

 

On R2, we say 'router ospf 1', network 10.0.0.0, and network 10.1.0.0 are both under Process ID 1, and now, R1 and R3 will learn routes to each other.

 

OSPF Configuration - network

 

We configured router OSPF, and usually, we'll use a Process ID of 1. The next command to use is the network command. This is pretty much the same as the network command we had for EIGRP as well.

 

So network, and then the network address, space, and the wildcard mask, which is the inverse of the subnet mask, and then specify the area. If you've got a small network, you can just put everything in area 0. The network command uses a wildcard mask rather than a subnet mask, which is the inverse of the subnet mask.

 

OSPF Configuration - network

 

If your subnet mask were 255.255.0.0, your wildcard mask would be 0.0.255.255. If your subnet mask were 255.255.255.252, your wildcard mask would be 0.0.0.3. To figure out the wildcard mask, subtract these octets in the subnet mask from 255.

 

Next thing, in EIGRP, if you specify the network statement and don't include a wildcard mask, it defaults to using the classful wildcard mask. For example, 0.255.255.255 for Class A. In OSPF, it does not default to doing that. You have to enter the wildcard mask in OSPF. If you try entering a network statement without a wildcard mask, it will give you an error message.

 

OSPF Configuration - network 2

 

What the network command means is the same as it was in EIGRP. Look for interfaces with an IP address within that range and then enable OSPF on those interfaces. Meaning sending out and listening for OSPF Hello messages and peering with adjacent OSPF routers. Once the adjacency has been formed, advertise the network and mask configured on those interfaces.

 

OSPF Configuration - network 3

 

OSPF Configuration Example - network

 

The same example as before for EIGRP, we have R1 here. FastEthernet0/0 has got IP address 10.1.0.1/24, FastEthernet1/0 is on the 10.0.1.0/24 network, and FastEthernet2/0 is on the 10.0.2.0/24 network.

 

We could put in 3 separate network statements to cover each of the interfaces, or we could just cover them all with just one network statement. In the example here, we just want to turn on OSPF for interfaces FastEthernet1/0 and FastEthernet2/0. We don't want to include FastEthernet0/0. We configure our network command, 'network 10.0.0.0 0.0.255.255 area 0'.

 

OSPF Configuration Example - network

 

All interfaces have an IP address that begins with 10.0, and then anything after that, we're going to turn OSPF on for those interfaces. So that will match on interface FastEthernet1/0 and FastEthernet2/0. FastEthernet0/0 begins with 10.1, so that is not included in the network statement.

 

So, we're not going to turn OSPF on there. The networks that will be advertised are 10.0.1.0/24 because that's the subnet configured on the interface and 10.0.2.0/24. We do not advertise 10.0.0.0/16, which we configured in the network statement.

 

The network statement does not say to advertise this subnet. The network statement says to look for interfaces that fall within this range, enable OSPF on interfaces, and then advertise with a subnet configured on that interface.

 

OSPF Verification – show run | section ospf

 

To see your OSPF configuration, we can do a 'show run' and then pipe '|' it to 'section ospf'. That will show all of the OSPF commands in your running config, whether they're under the main OSPF part of the configuration or at the interface level.

 

OSPF Verification – show run | section ospf

 

It is convenient to see all your OSPF commands. It’s easier than doing a 'show run' and trying to scroll down to the actual part of the config.

 

OSPF Verification - show ip protocols

 

The 'show ip protocols' will show all the routing protocols running on the router. You can see in the example that we're running OSPF with Process ID 1. You can see other information, like the networks it's routing for, the routing information sources, which are the OSPF neighbors, etc.

 

OSPF Verification - show ip protocols

 

OSPF Verification – show ip ospf interface brief

 

The 'show ip ospf interface brief' will show which interfaces have got OSPF enabled on them on this router, the Process ID for the interface, the area, the IP address and mask, the cost for the metric, and how many neighbors are reachable through that interface.

 

OSPF Verification – show ip ospf interface brief

 

OSPF Operations

 

With the OSPF operations that run in the router after you enable it, the first thing it does is it discovers neighbors and form adjacencies. So if you're going to verify that OSPF is working, it makes sense that the first thing to check is that it has been able to form adjacencies.

 

OSPF Operations

 

OSPF Verification – show ip ospf neighbor

 

Whenever I configure OSPF, the first command I always do after that once I've configured both sides of the link is 'show ip ospf neighbor', check that the routers can see each other and have formed an adjacency. In the example, the neighbor ID is 10.0.2.1, and it is reachable out interface FastEthernet0/0.

 

OSPF Verification – show ip ospf neighbor

 

OSPF Operations - LSDB

 

The next thing that happens with OSPF operations is that the routers will flood the Link State Database (LSDB).

 

OSPF Operations - LSDB

 

OSPF Verification – show ip ospf database

 

To see if routes have been learned from OSPF, you can use the 'show ip ospf database' command. That will show all the available links in that area and throughout the OSPF network.

 

OSPF Verification – show ip ospf database

 

OSPF Operations - Shortest Path First Algorithm

 

The next thing that happens is the routers will look at all the available possible paths, decide which is the best path using the Shortest Path First algorithm, and put that best path into the routing table.

 

OSPF Operations - Shortest Path First Algorithm

 

OSPF Verification – show ip route

 

The next command to verify is 'show ip route' and check that you've got OSPF routes in the routing table. Again, when I configure OSPF, the first command I'll use is 'show ip ospf neighbor', to check if the adjacency has come up. For the next command after that, I'll use a 'show ip route' and check that OSPF routes are in the routing table.

 

OSPF Verification – show ip route

 

I won't normally look at the database unless the routing table does not contain the routes I was expecting, and then, I'll use that more as a troubleshooting command.

 

OSPF Basic Configuration Example

 

This configuration example is taken from my free ‘Cisco CCNA Lab Guide’ which includes over 350 pages of lab exercises and full instructions to set up the lab for free on your laptop.

 

Click here to download your free Cisco CCNA Lab Guide.

 

YouTube video

 

OSPF Basic Configuration Example

 

  1. Enable a loopback interface on routers R1 to R5. Use the IP address 192.168.0.x/32, where ‘x’ is the router number. For example 192.168.0.3/32 on R3.

 

On routers R1 to R5:

R1(config)#interface loopback0

R1(config-if)#ip address 192.168.0.1 255.255.255.255

 

2. Enable single area OSPF on routers R1 to R5. Ensure all networks except 172.16.0.0/24 and 203.0.113.0/24 are advertised.

 

On routers R1 to R5:

R1(config)#router ospf 1

R1(config-router)#network 10.0.0.0 0.255.255.255 area 0

R1(config-router)#network 192.168.0.0 0.0.0.255 area 0

 

You can use different network statements as long as they cover the range of IP addresses configured on the router interfaces.

 

3. What do you expect the OSPF Router ID to be on R1? Verify this.

 

The loopback address is used for the Router ID, 192.168.0.1

 

R1#sh ip protocols

*** IP Routing is NSF aware ***

 

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 192.168.0.1

  Number of areas in this router is 1. 1 normal 0 stub 0 nssa

  Maximum path: 4

  Routing for Networks:

    10.0.0.0 0.255.255.255 area 0

    192.168.0.0 0.0.0.255 area 0

  Routing Information Sources:

    Gateway         Distance      Last Update

    192.168.0.1          110      00:00:25

    192.168.0.2          110      00:00:25

    192.168.0.3          110      00:00:25

    192.168.0.4          110      00:00:25

    192.168.0.5          110      00:00:25

  Distance: (default is 110)

 

4. Verify routers R1 to R5 have formed adjacencies with each other.

 

R1#show ip ospf neighbor

 

Neighbor ID     Pri   State           Dead Time   Address         Interface

192.168.0.5       1   FULL/BDR        00:00:31    10.0.3.2        FastEthernet1/1

192.168.0.2       1   FULL/DR         00:00:39    10.0.0.2        FastEthernet0/0

 

5. Verify all 10.x.x.x networks and loopbacks are in the routing tables on R1 to R5.

 

R1#sh ip route

Codes: L - local, C - connected, S - static, 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

       i - IS-IS, su - IS-IS summary, 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, H - NHRP, l - LISP

       + - replicated route, % - next hop override

 

Gateway of last resort is not set

 

10.0.0.0/8 is variably subnetted, 12 subnets, 2 masks

C 10.0.0.0/24 is directly connected, FastEthernet0/0

L 10.0.0.1/32 is directly connected, FastEthernet0/0

C 10.0.1.0/24 is directly connected, FastEthernet0/1

L 10.0.1.1/32 is directly connected, FastEthernet0/1

C 10.0.2.0/24 is directly connected, FastEthernet1/0

L 10.0.2.1/32 is directly connected, FastEthernet1/0

C 10.0.3.0/24 is directly connected, FastEthernet1/1

L 10.0.3.1/32 is directly connected, FastEthernet1/1

O 10.1.0.0/24 [110/2] via 10.0.0.2, 00:03:13, FastEthernet0/0

O 10.1.1.0/24 [110/3] via 10.0.0.2, 00:02:51, FastEthernet0/0

   [110/3] via 10.0.3.2, 00:02:51, FastEthernet1/1

O 10.1.2.0/24 [110/3] via 10.0.3.2, 00:02:51, FastEthernet1/1

O 10.1.3.0/24 [110/2] via 10.0.3.2, 00:02:51, FastEthernet1/1

192.168.0.0/32 is subnetted, 5 subnets

C 192.168.0.1/32 is directly connected, Loopback0

O 192.168.0.2/32 [110/2] via 10.0.0.2, 00:03:25, FastEthernet0/0

O 192.168.0.3/32 [110/3] via 10.0.0.2, 00:03:13, FastEthernet0/0

O 192.168.0.4/32 [110/3] via 10.0.3.2, 00:02:51, FastEthernet1/1

O 192.168.0.5/32 [110/2] via 10.0.3.2, 00:03:25, FastEthernet1/1

 

6. Set the reference bandwidth so that a 100 Gbps interface will have a cost of 1.

 

Remember to do this on all routers R1 to R5.

R1(config)#router ospf 1

R1(config-router)#auto-cost reference-bandwidth 100000

 

7. What will the OSPF cost be on the FastEthernet links? Verify this.

 

OSPF Cost = Reference bandwidth / Interface bandwidth.

100000 / 100 = 1000

 

R1#show ip ospf interface FastEthernet 0/0

 

FastEthernet0/0 is up, line protocol is up

Internet address is 10.0.0.1/24, Area 0

Process ID 1, Router ID 192.168.0.1, Network Type BROADCAST, Cost: 1000

 

8. What effect does this have on the cost to the 10.1.2.0/24 network from R1?

 

The cost changes from 3 to 3000.

Before reference bandwidth change:

 

R1#sh ip route

Codes: L - local, C - connected, S - static, 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

       i - IS-IS, su - IS-IS summary, 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, H - NHRP, l - LISP

       + - replicated route, % - next hop override

 

Gateway of last resort is not set

 

10.0.0.0/8 is variably subnetted, 12 subnets, 2 masks

C 10.0.0.0/24 is directly connected, FastEthernet0/0

L 10.0.0.1/32 is directly connected, FastEthernet0/0

C 10.0.1.0/24 is directly connected, FastEthernet0/1

L 10.0.1.1/32 is directly connected, FastEthernet0/1

C 10.0.2.0/24 is directly connected, FastEthernet1/0

L 10.0.2.1/32 is directly connected, FastEthernet1/0

C 10.0.3.0/24 is directly connected, FastEthernet1/1

L 10.0.3.1/32 is directly connected, FastEthernet1/1

O 10.1.0.0/24 [110/2] via 10.0.0.2, 00:03:13, FastEthernet0/0

O 10.1.1.0/24 [110/3] via 10.0.0.2, 00:02:51, FastEthernet0/0

   [110/3] via 10.0.3.2, 00:02:51, FastEthernet1/1

O 10.1.2.0/24 [110/3] via 10.0.3.2, 00:02:51, FastEthernet1/1

O 10.1.3.0/24 [110/2] via 10.0.3.2, 00:02:51, FastEthernet1/1

192.168.0.0/32 is subnetted, 5 subnets

C 192.168.0.1/32 is directly connected, Loopback0

O 192.168.0.2/32 [110/2] via 10.0.0.2, 00:03:25, FastEthernet0/0

O 192.168.0.3/32 [110/3] via 10.0.0.2, 00:03:13, FastEthernet0/0

O 192.168.0.4/32 [110/3] via 10.0.3.2, 00:02:51, FastEthernet1/1

O 192.168.0.5/32 [110/2] via 10.0.3.2, 00:03:25, FastEthernet1/1

 

After reference bandwidth change:

 

R1#sh ip route

Codes: L - local, C - connected, S - static, 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

       i - IS-IS, su - IS-IS summary, 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, H - NHRP, l - LISP

       + - replicated route, % - next hop override

 

Gateway of last resort is not set

 

10.0.0.0/8 is variably subnetted, 12 subnets, 2 masks

C 10.0.0.0/24 is directly connected, FastEthernet0/0

L 10.0.0.1/32 is directly connected, FastEthernet0/0

C 10.0.1.0/24 is directly connected, FastEthernet0/1

L 10.0.1.1/32 is directly connected, FastEthernet0/1

C 10.0.2.0/24 is directly connected, FastEthernet1/0

L 10.0.2.1/32 is directly connected, FastEthernet1/0

C 10.0.3.0/24 is directly connected, FastEthernet1/1

L 10.0.3.1/32 is directly connected, FastEthernet1/1

O 10.1.0.0/24 [110/2000] via 10.0.0.2, 00:01:04, FastEthernet0/0

O 10.1.1.0/24 [110/3000] via 10.0.0.2, 00:01:04, FastEthernet0/0

  [110/3000] via 10.0.3.2, 00:01:04, FastEthernet1/1

O 10.1.2.0/24 [110/3000] via 10.0.3.2, 00:01:04, FastEthernet1/1

O 10.1.3.0/24 [110/2000] via 10.0.3.2, 00:01:04, FastEthernet1/1

192.168.0.0/32 is subnetted, 5 subnets

C 192.168.0.1/32 is directly connected, Loopback0

O 192.168.0.2/32 [110/1012] via 10.0.0.2, 00:01:04, FastEthernet0/0

O 192.168.0.3/32 [110/2012] via 10.0.0.2, 00:01:04, FastEthernet0/0

O 192.168.0.4/32 [110/2012] via 10.0.3.2, 00:01:04, FastEthernet1/1

O 192.168.0.5/32 [110/1012] via 10.0.3.2, 00:01:04, FastEthernet1/1

 

Additional Resources

 

IP Routing: OSPF Configuration Guide: https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/iproute_ospf/configuration/xe-16/iro-xe-16-book/iro-cfg.html

OSPF Configuration: https://study-ccna.com/ospf-configuration/

Configuring OSPF in a Single Area: https://www.ciscopress.com/articles/article.asp?p=26919&seqNum=3

 

Want to practice Cisco CCNA technologies on your laptop? Download my complete 350-page Cisco CCNA Lab Guide for free.

 

Click Here to get my Cisco CCNA Gold Bootcamp, the highest rated CCNA course online with a 4.8 star rating from over 20,000 public reviews.

Libby Teofilo

Text by Libby Teofilo, Technical Writer at www.flackbox.com

With a mission to spread network awareness through writing, Libby consistently immerses herself into the unrelenting process of knowledge acquisition and dissemination. If not engrossed in technology, you might see her with a book in one hand and a coffee in the other.