Configuring OSPF - The Basics
We have to start somewhere so let’s look at the basics of configuring OSPF. Remember OSPF is an IGP (Interior Gateway Protocol) and allows packet authentication as well as IP multicast when sending and receiving updates. In this post we are configuring OSPF in a single area. In this topology we have four routers and two PCs. The PCs subnet are 172.30.2.0/24 and 172.30.3.0/24. We have point to point connections between each router.
So we have already configured all of interfaces and everything seems good but PC1 can’t ping PC2 and vice versa. If we do a show ip route on R1 we can see that R1 does not know about the 172.30.2.x or 172.30.3.x network as well as any other network not directly connected to R1.
1R1#show ip route
2Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
3 D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
4 N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
5 E1 - OSPF external type 1, E2 - OSPF external type 2
6 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
7 ia - IS-IS inter area, * - candidate default, U - per-user static route
8 o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
9 a - application route
10 + - replicated route, % - next hop override
11
12Gateway of last resort is not set
13
14 172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks
15C 172.16.0.8/30 is directly connected, GigabitEthernet0/1
16L 172.16.0.9/32 is directly connected, GigabitEthernet0/1
17C 172.16.0.12/30 is directly connected, GigabitEthernet0/2
18L 172.16.0.13/32 is directly connected, GigabitEthernet0/2
19C 172.16.128.0/30 is directly connected, GigabitEthernet0/3
20L 172.16.128.1/32 is directly connected, GigabitEthernet0/3
21 192.168.0.0/32 is subnetted, 1 subnets
22C 192.168.0.1 is directly connected, Loopback0
We also see the same issue with R3 if a routing protocol is not configured on router it will only know about its own active networks.
1R3#show ip route
2Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
3 D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
4 N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
5 E1 - OSPF external type 1, E2 - OSPF external type 2
6 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
7 ia - IS-IS inter area, * - candidate default, U - per-user static route
8 o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
9 a - application route
10 + - replicated route, % - next hop override
11
12Gateway of last resort is not set
13
14 172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks
15C 172.16.0.12/30 is directly connected, GigabitEthernet0/2
16L 172.16.0.14/32 is directly connected, GigabitEthernet0/2
17C 172.16.128.4/30 is directly connected, GigabitEthernet0/3
18L 172.16.128.6/32 is directly connected, GigabitEthernet0/3
19C 172.16.128.12/30 is directly connected, GigabitEthernet0/1
20L 172.16.128.13/32 is directly connected, GigabitEthernet0/1
21 172.30.0.0/16 is variably subnetted, 2 subnets, 2 masks
22C 172.30.3.0/24 is directly connected, GigabitEthernet0/4
23L 172.30.3.1/32 is directly connected, GigabitEthernet0/4
24 192.168.0.0/32 is subnetted, 1 subnets
25C 192.168.0.3 is directly connected, Loopback0
To configure OSPF you can do this in two ways. Let’s look at the traditional way to configure OSPF by jumping into to R1 and in the configuration mode let’s enter router ospf 1 followed by enter.
(NOTE: 1 is the process ID for OSPF you if you don’t what to use 1 we can pick between 1-65535, also this does not have match on each router).
We are now under a config-router prompt, the next thing we want to do is to tell the router what IP interface you want OSPF to run on. Looking at the network topology R1 has three interfaces let’s first choose the interface that uses the IP address 172.16.0.9 and put it in area 0. (Remember wildcard subnet masks)
1R1(config)#router ospf 1
2R1(config-router)#network 172.16.0.9 0.0.0.0 area 0
Side Conversation Area 0 is used for single-area configuration, you don’t have to use area 0 but it is recommended because Area 0 is special and not like the rest. If you ever needed two OSPF areas and they need to share routes together it won’t work without area 0 in the environment. Re-configuring a routing protocol on production may not be a good idea :). Another question that comes up when using the network command is why did I match the specific interface of 172.16.0.9? (network 172.16.0.9 0.0.0.0 ) Remember when we configure OSPF using the network command we are specifically looking at the individual interface of which we want OSPF sending and receiving updates. This is where it gets confusing because this command is not telling the router what to advertise it is simply telling the router which interfaces that you want OSPF running on. You could use the “lazy method” and allow all and future interfaces that the router has to use OSPF by using the command: (network 0.0.0.0 255.255.255.255). However this is a catch-22 because you are no longer in control of what interfaces that OSPF is running along with what networks are being added to OSPF. Future interfaces you configure on the router will be added to OSPF automatically and you may not want that. Personally and its a best practice to match the specific interfaces instead of using the lazy method.
So what just happened? Well nothing yet because R1 is this only router sending OSPF updates so let’s jump to R2 and run the following under the config-router prompt.
1R2(config)#router ospf 1
2R2(config-router)#network 172.16.0.10 0.0.0.0 area 0
3R2(config-router)#
4*Aug 13 01:49:33.888: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.0.1 on GigabitEthernet0/1 from LOADING to FULL, Loading Done
Notice the OSPF Adjacency that came up, this is good news because we now have OSPF running between R1 and R2 and they are exchanging updates between each other. We can verify this up looking at show ip ospf neighbor.
1R1#show ip ospf neighbor
2
3Neighbor ID Pri State Dead Time Address Interface
4192.168.0.2 1 FULL/BDR 00:00:30 172.16.0.10 GigabitEthernet0/1
Let’s get PC 2’s network advertised as well as all of the remaining interfaces on R1 and R2.
1R2(config)#router ospf 1
2R2(config-router)#network 172.30.2.1 0.0.0.0 area 0
3R2(config-router)#network 172.16.128.9 0.0.0.0 area 0
4R2(config-router)#network 172.16.128.5 0.0.0.0 area 0
5R1(config)#router ospf 1
6R1(config-router)#network 172.16.0.13 0.0.0.0 area 0
7R1(config-router)#network 172.16.128.1 0.0.0.0 area 0
Looking at the routing table in R1 we can see the 172.30.2.0/24 is reachable by leaving R1’s gigabitEthernet0/1 interface.
1R1#show ip route
2Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
3 D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
4 N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
5 E1 - OSPF external type 1, E2 - OSPF external type 2
6 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
7 ia - IS-IS inter area, * - candidate default, U - per-user static route
8 o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
9 a - application route
10 + - replicated route, % - next hop override
11
12Gateway of last resort is not set
13
14 172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks
15C 172.16.0.8/30 is directly connected, GigabitEthernet0/1
16L 172.16.0.9/32 is directly connected, GigabitEthernet0/1
17C 172.16.0.12/30 is directly connected, GigabitEthernet0/2
18L 172.16.0.13/32 is directly connected, GigabitEthernet0/2
19C 172.16.128.0/30 is directly connected, GigabitEthernet0/3
20L 172.16.128.1/32 is directly connected, GigabitEthernet0/3
21 172.30.0.0/24 is subnetted, 1 subnets
22O 172.30.2.0 [110/2] via 172.16.0.10, 00:03:39, GigabitEthernet0/1
23 192.168.0.0/32 is subnetted, 1 subnets
24C 192.168.0.1 is directly connected, Loopback0
So depending if you have a newer IOS software there is another way to configure OSPF instead of using the network command while in the (config-router) prompt. This newer method is configured by going under the interface of which you want OSPF to run. Let’s configure it on R3 and R4. We still have to switch on OSPF by running the router ospf 1 command but then we can go to the interfaces.
1R4(config)#router ospf 1
2R3(config)#router ospf 1
Now let’s go to gigabitethernet0/1 on R4 and tell OSPF this is the interface we want OSPF running on. Also notice the adjacency with R2 this is good news.
1R4(config)#interface gigabitEthernet 0/1
2R4(config-if)#ip ospf 1 area 0
3*Aug 13 01:50:10.698: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.0.2 on GigabitEthernet0/1 from LOADING to FULL, Loading Done
Let’s continue this on all remaining interfaces on R4 and R3.
1R4(config)#
2R4(config)#interface gigabitEthernet 0/2
3R4(config-if)#ip ospf 1 area 0
4R4(config-if)#exit
5R4(config)#interface gigabitEthernet 0/3
6R4(config-if)#ip ospf 1 area 0
7R4(config-if)#exit
8*Aug 13 01:55:07.905: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.0.1 on GigabitEthernet0/3 from LOADING to FULL, Loading Done
9R4(config)#
10
11--ROUTER 3 --
12
13R3(config)#interface gigabitEthernet 0/1
14R3(config-if)#ip ospf 1 area 0
15R3(config-if)#exit
16*Aug 13 01:58:39.091: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.0.4 on GigabitEthernet0/1 from LOADING to FULL, Loading Done
17R3(config)#interface gigabitEthernet 0/2
18R3(config-if)#ip ospf 1 area 0
19R3(config-if)#exit
20*Aug 13 01:59:01.142: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.0.1 on GigabitEthernet0/2 from LOADING to FULL, Loading Done
21R3(config)#interface gigabitEthernet 0/3
22R3(config-if)#ip ospf 1 area 0
23R3(config-if)#exit
24*Aug 13 01:59:37.701: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.0.2 on GigabitEthernet0/3 from LOADING to FULL, Loading Done
25R3(config)#interface gigabitEthernet 0/4
26R3(config-if)#ip ospf 1 area 0
27R3(config-if)#exit
28R3(config)#
We now have OSPF setup. We can verify this by typing show ip ospf neighbor.
1R1#show ip ospf neighbor
2
3Neighbor ID Pri State Dead Time Address Interface
4192.168.0.4 1 FULL/BDR 00:00:35 172.16.128.2 GigabitEthernet0/3
5192.168.0.3 1 FULL/BDR 00:00:35 172.16.0.14 GigabitEthernet0/2
6192.168.0.2 1 FULL/DR 00:00:31 172.16.0.10 GigabitEthernet0/1
7
8------
9R2#show ip ospf neighbor
10
11Neighbor ID Pri State Dead Time Address Interface
12192.168.0.3 1 FULL/BDR 00:00:38 172.16.128.6 GigabitEthernet0/3
13192.168.0.4 1 FULL/DR 00:00:35 172.16.128.10 GigabitEthernet0/2
14192.168.0.1 1 FULL/BDR 00:00:34 172.16.0.9 GigabitEthernet0/1
15
16-------
17R3#show ip ospf neighbor
18
19Neighbor ID Pri State Dead Time Address Interface
20192.168.0.2 1 FULL/DR 00:00:32 172.16.128.5 GigabitEthernet0/3
21192.168.0.1 1 FULL/DR 00:00:38 172.16.0.13 GigabitEthernet0/2
22192.168.0.4 1 FULL/DR 00:00:32 172.16.128.14 GigabitEthernet0/1
23
24--------
25R4#show ip ospf neighbor
26Neighbor ID Pri State Dead Time Address Interface
27192.168.0.1 1 FULL/DR 00:00:31 172.16.128.1 GigabitEthernet0/3
28192.168.0.3 1 FULL/BDR 00:00:33 172.16.128.13 GigabitEthernet0/2
29192.168.0.2 1 FULL/BDR 00:00:36 172.16.128.9 GigabitEthernet0/1
Let’s look at the routing table of R3, do we have route to 172.30.2.0/24 network? It looks like we do but why do we see only one route?
1R3#show ip route
2Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
3 D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
4 N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
5 E1 - OSPF external type 1, E2 - OSPF external type 2
6 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
7 ia - IS-IS inter area, * - candidate default, U - per-user static route
8 o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
9 a - application route
10 + - replicated route, % - next hop override
11
12Gateway of last resort is not set
13
14 172.16.0.0/16 is variably subnetted, 9 subnets, 2 masks
15O 172.16.0.8/30 [110/2] via 172.16.128.5, 00:02:06, GigabitEthernet0/3
16 [110/2] via 172.16.0.13, 00:02:45, GigabitEthernet0/2
17C 172.16.0.12/30 is directly connected, GigabitEthernet0/2
18L 172.16.0.14/32 is directly connected, GigabitEthernet0/2
19O 172.16.128.0/30
20 [110/2] via 172.16.128.14, 00:03:05, GigabitEthernet0/1
21 [110/2] via 172.16.0.13, 00:02:45, GigabitEthernet0/2
22C 172.16.128.4/30 is directly connected, GigabitEthernet0/3
23L 172.16.128.6/32 is directly connected, GigabitEthernet0/3
24O 172.16.128.8/30
25 [110/2] via 172.16.128.14, 00:03:05, GigabitEthernet0/1
26 [110/2] via 172.16.128.5, 00:02:06, GigabitEthernet0/3
27C 172.16.128.12/30 is directly connected, GigabitEthernet0/1
28L 172.16.128.13/32 is directly connected, GigabitEthernet0/1
29 172.30.0.0/16 is variably subnetted, 3 subnets, 2 masks
30O 172.30.2.0/24 [110/2] via 172.16.128.5, 00:02:06, GigabitEthernet0/3
31C 172.30.3.0/24 is directly connected, GigabitEthernet0/4
32L 172.30.3.1/32 is directly connected, GigabitEthernet0/4
33 192.168.0.0/32 is subnetted, 2 subnets
34O 192.168.0.1 [110/2] via 172.16.0.13, 00:02:45, GigabitEthernet0/2
35C 192.168.0.3 is directly connected, Loopback0
Remember that OSPF will choose the best path and put that path in the routing table. Going straight to R2 instead of going through R1 or R4. However OSPF knows about the other two routes which is why it is able to converge quickly. That's an important tip when comparing distance vector protocols vs link state protocols. In link state protocols routers know about the entire topology within an area and each router determines the shortest path to available destinations. So in case of a failure of the link the router would already know what path to take so there is no need to re-converge the routing table. Take a look at the routing table of R3 again after I disabled interface Gig0/3 on R2.
1R3#show ip route
2Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
3 D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
4 N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
5 E1 - OSPF external type 1, E2 - OSPF external type 2
6 i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
7 ia - IS-IS inter area, * - candidate default, U - per-user static route
8 o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
9 a - application route
10 + - replicated route, % - next hop override
11
12Gateway of last resort is not set
13
14 172.16.0.0/16 is variably subnetted, 9 subnets, 2 masks
15O 172.16.0.8/30 [110/2] via 172.16.0.13, 01:04:20, GigabitEthernet0/2
16C 172.16.0.12/30 is directly connected, GigabitEthernet0/2
17L 172.16.0.14/32 is directly connected, GigabitEthernet0/2
18O 172.16.128.0/30
19 [110/2] via 172.16.128.14, 01:04:40, GigabitEthernet0/1
20 [110/2] via 172.16.0.13, 01:04:20, GigabitEthernet0/2
21C 172.16.128.4/30 is directly connected, GigabitEthernet0/3
22L 172.16.128.6/32 is directly connected, GigabitEthernet0/3
23O 172.16.128.8/30
24 [110/2] via 172.16.128.14, 01:04:40, GigabitEthernet0/1
25C 172.16.128.12/30 is directly connected, GigabitEthernet0/1
26L 172.16.128.13/32 is directly connected, GigabitEthernet0/1
27 172.30.0.0/16 is variably subnetted, 3 subnets, 2 masks
28O 172.30.2.0/24 [110/3] via 172.16.128.14, 00:31:22, GigabitEthernet0/1
29 [110/3] via 172.16.0.13, 00:31:22, GigabitEthernet0/2
30C 172.30.3.0/24 is directly connected, GigabitEthernet0/4
31L 172.30.3.1/32 is directly connected, GigabitEthernet0/4
32 192.168.0.0/32 is subnetted, 2 subnets
33O 192.168.0.1 [110/2] via 172.16.0.13, 01:04:20, GigabitEthernet0/2
34C 192.168.0.3 is directly connected, Loopback0
35R3#
We can now see two routes to the 172.30.2.0 network. Since these paths are equal OSPF will balance between R1 and R4 to get the 172.30.2.0 network. This stays this way until the link between R2 and R3 comes back online. I'll end it here because that’s all I got for this post like always I hope this information is helpful in understanding the basics of OSPF with in a single area configuration. :)