Configuring single-area OSPF

I’ve been practicing IOS commands recently, I have created a single area OSPF network with an ASBR router in Packet Tracer. Just like in the previous post I’m going to share the commands I’ve issued on the routers with some explanation in order to remember them later. Let’s start with the network topology:

Single-area OSPF network in Cisco’s Packet Tracer
Single-area OSPF network in Cisco’s Packet Tracer

As mentioned before I’m going to apply a Dynamic Routing protocol within the network framed in orange in the picture above. I’ve decided to run OSPF because it’s one of the most popular routing protocols and there are a lot of resources on the internet to learn it. At the end of the post I’ll define some static routes with custom AD values as well.

Let’s start the configuration: I skipped the part where I assigned IP addresses to interfaces, specified the IP addresses and default gateways for the hosts. First I defined a loopback interface for every router, it’ll be the router ID for every router in OSPF. Also made them passive interfaces since we don’t need to advertise OSPF on them. Next I specified which interfaces I would like to run OSPF on with the <network ... > command. This can be done in many ways, I defined the interfaces with the /32 network mask. Finally I set the default cost 10 000 on all routers, since we only have Gigabit interfaces and no FastEthernet this won’t have any effect on the network.

R1:

R1>enable
R1#configu terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#interface loopback0

R1(config-if)#
%LINK-5-CHANGED: Interface Loopback0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up

R1(config-if)#ip address 192.168.1.11 255.255.255.255
R1(config-if)#router ospf 1
R1(config-router)#network 10.0.12.1 0.0.0.0 area 0
R1(config-router)#network 10.0.13.1 0.0.0.0 area 0
R1(config-router)#network 192.168.1.11 0.0.0.0 area 0
R1(config-router)#passive-interface loopback0
R1(config-router)#auto-cost reference-bandwidth ?
  <1-4294967>  The reference bandwidth in terms of Mbits per second
R1(config-router)#auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
        Please ensure reference bandwidth is consistent across all routers.

R2:

R2>
R2>enable
R2#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#interface loopback0

R2(config-if)#
%LINK-5-CHANGED: Interface Loopback0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up

R2(config-if)#ip address 192.168.1.22 255.255.255.255
R2(config-if)#router ospf 1
R2(config-router)#network 10.0.12.2 0.0.0.0 area 0
R2(config-router)#network 10.0.24
00:28:34: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.1.11 on GigabitEthernet0/0 from LOADING to FULL, Loading Done

                          ^
% Invalid input detected at '^' marker.
	
R2(config-router)#network 10.0.24.1 0.0.0.0 area 0
R2(config-router)#network 192.168.1.22 0.0.0.0 area 0
R2(config-router)#passive-interface loopback0
R2(config-router)#auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
        Please ensure reference bandwidth is consistent across all routers.
R2(config-router)#network 192.168.100.254 0.0.0.0 area 0
R2(config-router)#passive-interface Gi0/2

R4:

R4>enable
R4#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R4(config)#interface loopback0

R4(config-if)#
%LINK-5-CHANGED: Interface Loopback0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up

R4(config-if)#ip address 192.168.1.44 255.255.255.255
R4(config-if)#router ospf 1
R4(config-router)#network 10.0.24.2 0.0.0.0 area 0
R4(config-router)#network 
00:41:09: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.1.22 on GigabitEthernet0/0 from LOADING to FULL, Loading Done

R4#
%SYS-5-CONFIG_I: Configured from console by console

R4#router ospf 1
          ^
% Invalid input detected at '^' marker.
	
R4#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R4(config)#router ospf 1
R4(config-router)#network 10.0.34.2 0.0.0.0 area 0
R4(config-router)#network 192.168.1.44 0.0.0.0 area 0
R4(config-router)#passive-interface loopback0
R4(config-router)#auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
        Please ensure reference bandwidth is consistent across all routers.

R3 is an interesting one: It’s the boundary router (ASBR), so I define the default gateway here to the external network with the ip route 0.0.0.0 0.0.0.0 <IP address> command and “advertise” it with the default-information originate command.

R3>enable
R3#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R3(config)#interface loopback0
R3(config-if)#ip address 192.168.1.33 255.255.255.255
R3(config-if)#
R3(config-if)#router ospf 1
R3(config-router)#network 10.0.13.2 0.0.0.0 area 0
R3(config-router)#network 10.0.34.1 0.0.0.0 a
01:01:11: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.1.11 on GigabitEthernet0/1 from LOAnetwork 10.0.34.1 0.0.0.0 area 0
R3(config-router)#
01:01:39: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.1.44 on GigabitEthernet0/0 from LOADING to FULL, Loading Done

R3(config-router)#network 192.168.1.33 0.0.0.0 area 0
R3(config-router)#passive-interface loopback0
R3(config-router)#auto-cost reference-bandwidth 10000
% OSPF: Reference bandwidth is changed.
        Please ensure reference bandwidth is consistent across all routers.
        
R3(config)#ip route 0.0.0.0 0.0.0.0 172.16.0.2
R3(config)#router ospf 1
R3(config-router)#default-information originate

Let’s see some show commands to make sure OSPF works:

R1#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
GigabitEthernet0/0     10.0.12.1       YES manual up                    up 
GigabitEthernet0/1     10.0.13.1       YES manual up                    up 
GigabitEthernet0/2     unassigned      YES unset  administratively down down 
Loopback0              192.168.1.11    YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down
R1#show ip protocols

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.1.11
  Number of areas in this router is 1. 1 normal 0 stub 0 nssa
  Maximum path: 4
  Routing for Networks:
    10.0.12.1 0.0.0.0 area 0
    10.0.13.1 0.0.0.0 area 0
    192.168.1.11 0.0.0.0 area 0
  Passive Interface(s): 
    Loopback0
  Routing Information Sources:  
    Gateway         Distance      Last Update 
    192.168.1.11         110      00:03:04
    192.168.1.22         110      00:23:04
    192.168.1.33         110      00:24:11
    192.168.1.44         110      00:02:35
  Distance: (default is 110)

R1#show 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, E - EGP
       i - IS-IS, 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

Gateway of last resort is 10.0.13.2 to network 0.0.0.0

     10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
C       10.0.12.0/30 is directly connected, GigabitEthernet0/0
L       10.0.12.1/32 is directly connected, GigabitEthernet0/0
C       10.0.13.0/30 is directly connected, GigabitEthernet0/1
L       10.0.13.1/32 is directly connected, GigabitEthernet0/1
O       10.0.24.0/30 [110/20] via 10.0.12.2, 00:53:28, GigabitEthernet0/0
O       10.0.34.0/30 [110/20] via 10.0.13.2, 00:29:47, GigabitEthernet0/1
     192.168.1.0/32 is subnetted, 4 subnets
C       192.168.1.11/32 is directly connected, Loopback0
O       192.168.1.22/32 [110/11] via 10.0.12.2, 01:04:24, GigabitEthernet0/0
O       192.168.1.33/32 [110/11] via 10.0.13.2, 00:30:30, GigabitEthernet0/1
O       192.168.1.44/32 [110/21] via 10.0.12.2, 00:29:47, GigabitEthernet0/0
                        [110/21] via 10.0.13.2, 00:29:47, GigabitEthernet0/1
O    192.168.100.0/24 [110/20] via 10.0.12.2, 01:02:32, GigabitEthernet0/0
O*E2 0.0.0.0/0 [110/1] via 10.0.13.2, 00:24:31, GigabitEthernet0/1

R1#show ip ospf neighbor


Neighbor ID     Pri   State           Dead Time   Address         Interface
192.168.1.22      1   FULL/BDR        00:00:39    10.0.12.2       GigabitEthernet0/0
192.168.1.33      1   FULL/BDR        00:00:30    10.0.13.2       GigabitEthernet0/1
R1#


R2#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
GigabitEthernet0/0     10.0.12.2       YES manual up                    up 
GigabitEthernet0/1     10.0.24.1       YES manual up                    up 
GigabitEthernet0/2     192.168.100.254 YES manual up                    up 
Loopback0              192.168.1.22    YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down
R2#show ip protocol

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.1.22
  Number of areas in this router is 1. 1 normal 0 stub 0 nssa
  Maximum path: 4
  Routing for Networks:
    10.0.12.2 0.0.0.0 area 0
    10.0.24.1 0.0.0.0 area 0
    192.168.1.22 0.0.0.0 area 0
    192.168.100.254 0.0.0.0 area 0
  Passive Interface(s): 
    GigabitEthernet0/2
    Loopback0
  Routing Information Sources:  
    Gateway         Distance      Last Update 
    192.168.1.11         110      00:05:14
    192.168.1.22         110      00:25:12
    192.168.1.33         110      00:26:20
    192.168.1.44         110      00:04:44
  Distance: (default is 110)

R2#show 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, E - EGP
       i - IS-IS, 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

Gateway of last resort is 10.0.12.1 to network 0.0.0.0

     10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
C       10.0.12.0/30 is directly connected, GigabitEthernet0/0
L       10.0.12.2/32 is directly connected, GigabitEthernet0/0
O       10.0.13.0/30 [110/20] via 10.0.12.1, 00:35:13, GigabitEthernet0/0
C       10.0.24.0/30 is directly connected, GigabitEthernet0/1
L       10.0.24.1/32 is directly connected, GigabitEthernet0/1
O       10.0.34.0/30 [110/20] via 10.0.24.2, 00:34:45, GigabitEthernet0/1
     192.168.1.0/32 is subnetted, 4 subnets
O       192.168.1.11/32 [110/11] via 10.0.12.1, 01:05:31, GigabitEthernet0/0
C       192.168.1.22/32 is directly connected, Loopback0
O       192.168.1.33/32 [110/21] via 10.0.12.1, 00:32:22, GigabitEthernet0/0
                        [110/21] via 10.0.24.2, 00:32:22, GigabitEthernet0/1
O       192.168.1.44/32 [110/11] via 10.0.24.2, 00:53:40, GigabitEthernet0/1
     192.168.100.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.100.0/24 is directly connected, GigabitEthernet0/2
L       192.168.100.254/32 is directly connected, GigabitEthernet0/2
O*E2 0.0.0.0/0 [110/1] via 10.0.12.1, 00:26:23, GigabitEthernet0/0
               [110/1] via 10.0.24.2, 00:26:23, GigabitEthernet0/1

R2#show ip ospf neighbor


Neighbor ID     Pri   State           Dead Time   Address         Interface
192.168.1.11      1   FULL/DR         00:00:32    10.0.12.1       GigabitEthernet0/0
192.168.1.44      1   FULL/BDR        00:00:36    10.0.24.2       GigabitEthernet0/1
R2#

R3#show ip interface brief
Interface              IP-Address      OK? Method Status                Protocol 
GigabitEthernet0/0     10.0.34.1       YES manual up                    up 
GigabitEthernet0/1     10.0.13.2       YES manual up                    up 
GigabitEthernet0/2     172.16.0.1      YES manual up                    up 
Loopback0              192.168.1.33    YES manual up                    up 
Vlan1                  unassigned      YES unset  administratively down down
R3#show ip protocol

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.1.33
  It is an autonomous system boundary router
  Redistributing External Routes from,
  Number of areas in this router is 1. 1 normal 0 stub 0 nssa
  Maximum path: 4
  Routing for Networks:
    10.0.13.2 0.0.0.0 area 0
    10.0.34.1 0.0.0.0 area 0
    192.168.1.33 0.0.0.0 area 0
  Passive Interface(s): 
    Loopback0
  Routing Information Sources:  
    Gateway         Distance      Last Update 
    192.168.1.11         110      00:07:15
    192.168.1.22         110      00:27:15
    192.168.1.33         110      00:28:22
    192.168.1.44         110      00:06:46
  Distance: (default is 110)

R3#show 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, E - EGP
       i - IS-IS, 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

Gateway of last resort is 172.16.0.2 to network 0.0.0.0

     10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
O       10.0.12.0/30 [110/20] via 10.0.13.1, 00:33:53, GigabitEthernet0/1
C       10.0.13.0/30 is directly connected, GigabitEthernet0/1
L       10.0.13.2/32 is directly connected, GigabitEthernet0/1
O       10.0.24.0/30 [110/20] via 10.0.34.2, 00:33:53, GigabitEthernet0/0
C       10.0.34.0/30 is directly connected, GigabitEthernet0/0
L       10.0.34.1/32 is directly connected, GigabitEthernet0/0
     172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C       172.16.0.0/30 is directly connected, GigabitEthernet0/2
L       172.16.0.1/32 is directly connected, GigabitEthernet0/2
     192.168.1.0/32 is subnetted, 4 subnets
O       192.168.1.11/32 [110/11] via 10.0.13.1, 00:33:53, GigabitEthernet0/1
O       192.168.1.22/32 [110/21] via 10.0.13.1, 00:33:53, GigabitEthernet0/1
                        [110/21] via 10.0.34.2, 00:33:53, GigabitEthernet0/0
C       192.168.1.33/32 is directly connected, Loopback0
O       192.168.1.44/32 [110/11] via 10.0.34.2, 00:33:53, GigabitEthernet0/0
O    192.168.100.0/24 [110/30] via 10.0.13.1, 00:33:53, GigabitEthernet0/1
                      [110/30] via 10.0.34.2, 00:33:53, GigabitEthernet0/0
S*   0.0.0.0/0 [1/0] via 172.16.0.2

R3#show ip ospf neighbor


Neighbor ID     Pri   State           Dead Time   Address         Interface
192.168.1.44      1   FULL/DR         00:00:39    10.0.34.2       GigabitEthernet0/0
192.168.1.11      1   FULL/DR         00:00:31    10.0.13.1       GigabitEthernet0/1

It can be seen which interfaces is OSPF enabled on, the FULL State of the OSPF neighbors, the OSPF dead interval (40 sec by default, it resets at 30 sec [-10 sec hello time interval]) and most importantly the OSPF entries of the routing table and the default gateway to the external network.

I pinged PC2 from PC1, the ping was successful. But I noticed that the route between PC1 and PC2 was variable: R2 and R3 did load-balance through R1 and R4, as every interface has the speed of 1 Gbps the paths have the same cost.

I wanted to direct the traffic to the bottom path only (R3-R4-R2) so I specified static routes on R3 and R2 with the AD value of 100 for practicing. By default the static routes have the AD value of 1 (it’s already less than 110), so it’s not really necessary.

R2(config)#ip route 172.16.1.0 255.255.255.0 10.0.24.2 ?
  <1-255>  Distance metric for this route
  <cr>
R2(config)#ip route 172.16.1.0 255.255.255.0 10.0.24.2 100
R2(config)#do show 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, E - EGP
       i - IS-IS, 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

Gateway of last resort is 10.0.12.1 to network 0.0.0.0

     10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
C       10.0.12.0/30 is directly connected, GigabitEthernet0/0
L       10.0.12.2/32 is directly connected, GigabitEthernet0/0
O       10.0.13.0/30 [110/20] via 10.0.12.1, 00:03:14, GigabitEthernet0/0
C       10.0.24.0/30 is directly connected, GigabitEthernet0/1
L       10.0.24.1/32 is directly connected, GigabitEthernet0/1
O       10.0.34.0/30 [110/20] via 10.0.24.2, 00:03:24, GigabitEthernet0/1
     172.16.0.0/24 is subnetted, 1 subnets
S       172.16.1.0/24 [100/0] via 10.0.24.2
     192.168.1.0/32 is subnetted, 4 subnets
O       192.168.1.11/32 [110/11] via 10.0.12.1, 00:03:24, GigabitEthernet0/0
C       192.168.1.22/32 is directly connected, Loopback0
O       192.168.1.33/32 [110/21] via 10.0.12.1, 00:03:14, GigabitEthernet0/0
                        [110/21] via 10.0.24.2, 00:03:14, GigabitEthernet0/1
O       192.168.1.44/32 [110/11] via 10.0.24.2, 00:03:24, GigabitEthernet0/1
     192.168.100.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.100.0/24 is directly connected, GigabitEthernet0/2
L       192.168.100.254/32 is directly connected, GigabitEthernet0/2
O*E2 0.0.0.0/0 [110/1] via 10.0.12.1, 00:03:14, GigabitEthernet0/0
               [110/1] via 10.0.24.2, 00:03:14, GigabitEthernet0/1

R2(config)#

R3(config)#ip route 192.168.100.0 255.255.255.0 10.0.34.2 ?
  <1-255>  Distance metric for this route
  <cr>
R3(config)#ip route 192.168.100.0 255.255.255.0 10.0.34.2 100
R3(config)#do show 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, E - EGP
       i - IS-IS, 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

Gateway of last resort is 172.16.0.2 to network 0.0.0.0

     10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
O       10.0.12.0/30 [110/20] via 10.0.13.1, 00:04:41, GigabitEthernet0/1
C       10.0.13.0/30 is directly connected, GigabitEthernet0/1
L       10.0.13.2/32 is directly connected, GigabitEthernet0/1
O       10.0.24.0/30 [110/20] via 10.0.34.2, 00:04:51, GigabitEthernet0/0
C       10.0.34.0/30 is directly connected, GigabitEthernet0/0
L       10.0.34.1/32 is directly connected, GigabitEthernet0/0
     172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C       172.16.0.0/30 is directly connected, GigabitEthernet0/2
L       172.16.0.1/32 is directly connected, GigabitEthernet0/2
     192.168.1.0/32 is subnetted, 4 subnets
O       192.168.1.11/32 [110/11] via 10.0.13.1, 00:04:41, GigabitEthernet0/1
O       192.168.1.22/32 [110/21] via 10.0.34.2, 00:04:41, GigabitEthernet0/0
                        [110/21] via 10.0.13.1, 00:04:41, GigabitEthernet0/1
C       192.168.1.33/32 is directly connected, Loopback0
O       192.168.1.44/32 [110/11] via 10.0.34.2, 00:04:51, GigabitEthernet0/0
S    192.168.100.0/24 [100/0] via 10.0.34.2
S*   0.0.0.0/0 [1/0] via 172.16.0.2

I checked it with the traceroute command, the ICMP packets were going through the bottom path:

C:\>tracert 172.16.1.1

Tracing route to 172.16.1.1 over a maximum of 30 hops: 

  1   0 ms      0 ms      0 ms      192.168.100.254
  2   0 ms      0 ms      0 ms      10.0.24.2
  3   0 ms      0 ms      0 ms      10.0.34.1
  4   0 ms      0 ms      0 ms      172.16.0.2
  5   0 ms      0 ms      0 ms      172.16.1.1

Trace complete.