OSPF is the routing protocol you will meet most often in CCNA and in real enterprise networks. In this lab you will configure single-area OS...
OSPF is the routing protocol you will meet most often in CCNA and in real enterprise networks. In this lab you will configure single-area OSPFv2 (area 0) on three routers in Cisco Packet Tracer 8.x, set router IDs, make LAN interfaces passive, and verify everything with the show commands that matter. By the end, every PC will be able to reach every other PC without a single static route.
Prefer video? Watch more hands-on labs on the Technical Hakim YouTube channel.
OSPF in two minutes
OSPF (Open Shortest Path First) is a link-state protocol. Each router describes its own links in Link-State Advertisements (LSAs), floods them to all routers in the area, and then every router runs the SPF (Dijkstra) algorithm on the same database to build its routing table. A few terms you need for this lab:
- Process ID: the number in
router ospf 1. It is local to the router and does not have to match between neighbors. - Area: a group of routers that share the same link-state database. Single-area designs use area 0, the backbone. The area must match on both ends of a link.
- Router ID (RID): a 32-bit value written like an IP address that uniquely identifies the router. If you do not set it, IOS picks the highest loopback IP, or else the highest active interface IP.
- Cost: the OSPF metric. By default it is 100 Mbps divided by the interface bandwidth, with a minimum of 1. A GigabitEthernet interface therefore has a cost of 1.
- DR/BDR: on Ethernet (broadcast) segments, OSPF elects a Designated Router and Backup Designated Router to reduce flooding.
Lab topology
Three Cisco 2911 routers are connected in a triangle using GigabitEthernet links. Each router also has a LAN on G0/2 with a 2960 switch and one PC.
Addressing table
| Device | Interface | IP address | Mask | Connected to |
|---|---|---|---|---|
| R1 | G0/0 | 10.0.12.1 | 255.255.255.252 | R2 G0/0 |
| R1 | G0/1 | 10.0.13.1 | 255.255.255.252 | R3 G0/1 |
| R1 | G0/2 | 192.168.1.1 | 255.255.255.0 | LAN 1 (PC1) |
| R2 | G0/0 | 10.0.12.2 | 255.255.255.252 | R1 G0/0 |
| R2 | G0/1 | 10.0.23.1 | 255.255.255.252 | R3 G0/0 |
| R2 | G0/2 | 192.168.2.1 | 255.255.255.0 | LAN 2 (PC2) |
| R3 | G0/0 | 10.0.23.2 | 255.255.255.252 | R2 G0/1 |
| R3 | G0/1 | 10.0.13.2 | 255.255.255.252 | R1 G0/1 |
| R3 | G0/2 | 192.168.3.1 | 255.255.255.0 | LAN 3 (PC3) |
| PC1 | Fa0 | 192.168.1.10 | 255.255.255.0 | Gateway 192.168.1.1 |
| PC2 | Fa0 | 192.168.2.10 | 255.255.255.0 | Gateway 192.168.2.1 |
| PC3 | Fa0 | 192.168.3.10 | 255.255.255.0 | Gateway 192.168.3.1 |
Router IDs: R1 = 1.1.1.1, R2 = 2.2.2.2, R3 = 3.3.3.3.
Step 1: Interface addressing
Configure every interface from the table first and confirm it is up/up before touching OSPF. Here is R1; R2 and R3 follow the same pattern.
Router> enable
Router# configure terminal
Router(config)# hostname R1
R1(config)# interface gigabitEthernet 0/0
R1(config-if)# description Link to R2
R1(config-if)# ip address 10.0.12.1 255.255.255.252
R1(config-if)# no shutdown
R1(config-if)# interface gigabitEthernet 0/1
R1(config-if)# description Link to R3
R1(config-if)# ip address 10.0.13.1 255.255.255.252
R1(config-if)# no shutdown
R1(config-if)# interface gigabitEthernet 0/2
R1(config-if)# description LAN 1
R1(config-if)# ip address 192.168.1.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# end
Before moving on, ping the directly connected neighbor (for example ping 10.0.12.2 from R1 once R2 is addressed). If a directly connected ping fails, OSPF will not fix it.
Step 2: Enable OSPF
R1
R1# configure terminal
R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R1(config-router)# network 10.0.12.0 0.0.0.3 area 0
R1(config-router)# network 10.0.13.0 0.0.0.3 area 0
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0
R1(config-router)# passive-interface gigabitEthernet 0/2
R1(config-router)# end
R2
R2# configure terminal
R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 10.0.12.0 0.0.0.3 area 0
R2(config-router)# network 10.0.23.0 0.0.0.3 area 0
R2(config-router)# network 192.168.2.0 0.0.0.255 area 0
R2(config-router)# passive-interface gigabitEthernet 0/2
R2(config-router)# end
R3
R3# configure terminal
R3(config)# router ospf 1
R3(config-router)# router-id 3.3.3.3
R3(config-router)# network 10.0.13.0 0.0.0.3 area 0
R3(config-router)# network 10.0.23.0 0.0.0.3 area 0
R3(config-router)# network 192.168.3.0 0.0.0.255 area 0
R3(config-router)# passive-interface gigabitEthernet 0/2
R3(config-router)# end
What each command does:
router ospf 1starts OSPF process 1 and enters router configuration mode.router-id 1.1.1.1sets a predictable RID. Set it before the network statements. If you change it later, IOS tells you to runclear ip ospf processfor the new ID to take effect.network 10.0.12.0 0.0.0.3 area 0enables OSPF on any interface whose IP falls inside 10.0.12.0 with wildcard 0.0.0.3 (the /30 range .0 to .3), and puts that interface in area 0. The network statement does not advertise a route by itself; it selects interfaces, and OSPF then advertises those interfaces' subnets.passive-interface gigabitEthernet 0/2stops OSPF hellos on the LAN while still advertising the LAN subnet. There are no routers on the PC side, so sending hellos there is a waste and a security risk.
As soon as two neighbors agree, you will see a log message like this on R1:
%OSPF-5-ADJCHG: Process 1, Nbr 2.2.2.2 on GigabitEthernet0/0 from LOADING to FULL, Loading Done
Alternative: interface-mode OSPF
Recent IOS versions, including the router images in Packet Tracer 8.x, also let you enable OSPF directly on the interface. This replaces the network statements and is easier to read:
R1(config)# interface gigabitEthernet 0/0
R1(config-if)# ip ospf 1 area 0
Pick one method per router and stay consistent so the configuration is easy to troubleshoot.
Step 3: Verification
Neighbors
R1# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/DR 00:00:33 10.0.12.2 GigabitEthernet0/0
3.3.3.3 1 FULL/DR 00:00:31 10.0.13.2 GigabitEthernet0/1
Both neighbors must be in the FULL state. The part after the slash is the neighbor's role on that segment. In my lab, R1 has the lowest router ID, so its neighbors became DR on both links. In your lab the DR roles may differ, because the DR election is not preemptive: whichever router comes up first can win. That is normal and does not affect reachability.
R2# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
1.1.1.1 1 FULL/BDR 00:00:36 10.0.12.1 GigabitEthernet0/0
3.3.3.3 1 FULL/DR 00:00:39 10.0.23.2 GigabitEthernet0/1
Routing table
R1# show ip route ospf
10.0.0.0/8 is variably subnetted, 5 subnets, 2 masks
O 10.0.23.0/30 [110/2] via 10.0.12.2, 00:05:12, GigabitEthernet0/0
[110/2] via 10.0.13.2, 00:05:12, GigabitEthernet0/1
O 192.168.2.0/24 [110/2] via 10.0.12.2, 00:05:12, GigabitEthernet0/0
O 192.168.3.0/24 [110/2] via 10.0.13.2, 00:05:02, GigabitEthernet0/1
Read [110/2] as administrative distance 110 (OSPF) and a cost of 2. To reach 192.168.2.0/24, R1 adds its own G0/0 cost (1) to R2's G0/2 cost (1). The R2–R3 link 10.0.23.0/30 is reachable at equal cost through both R2 and R3, so OSPF installs both paths and load-balances. By default IOS allows up to four equal-cost paths.
Protocol summary
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 1.1.1.1
Number of areas in this router is 1. 1 normal 0 stub 0 nssa
Maximum path: 4
Routing for Networks:
10.0.12.0 0.0.0.3 area 0
10.0.13.0 0.0.0.3 area 0
192.168.1.0 0.0.0.255 area 0
Passive Interface(s):
GigabitEthernet0/2
Routing Information Sources:
Gateway Distance Last Update
2.2.2.2 110 00:05:20
3.3.3.3 110 00:05:10
Distance: (default is 110)
This one command confirms the router ID, every network statement, and which interfaces are passive. It is my first stop when a neighbor will not come up.
Interface details
R1# show ip ospf interface gigabitEthernet 0/0
GigabitEthernet0/0 is up, line protocol is up
Internet address is 10.0.12.1/30, Area 0
Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State BDR, Priority 1
Designated Router (ID) 2.2.2.2, Interface address 10.0.12.2
Backup Designated Router (ID) 1.1.1.1, Interface address 10.0.12.1
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:04
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 2.2.2.2 (Designated Router)
Suppress hello for 0 neighbor(s)
Here you can check the area, cost, network type and the hello/dead timers (10 and 40 seconds by default on Ethernet). Timers must match on both sides for an adjacency to form. (Output trimmed slightly.)
End-to-end test
C:\>ping 192.168.3.10
Pinging 192.168.3.10 with 32 bytes of data:
Reply from 192.168.3.10: bytes=32 time<1ms TTL=126
Reply from 192.168.3.10: bytes=32 time<1ms TTL=126
Reply from 192.168.3.10: bytes=32 time<1ms TTL=126
Reply from 192.168.3.10: bytes=32 time<1ms TTL=126
Ping statistics for 192.168.3.10:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
TTL 126 from PC1 means two routers were crossed (R1 and R3), which matches the shortest path.
Optional: adjust the reference bandwidth
With the default reference of 100 Mbps, FastEthernet and GigabitEthernet both get cost 1, so OSPF cannot tell them apart. On real networks I raise the reference on every router:
R1(config)# router ospf 1
R1(config-router)# auto-cost reference-bandwidth 1000
% OSPF: Reference bandwidth is changed.
Please ensure reference bandwidth is consistent across all routers.
The value is in Mbps. After this change a GigabitEthernet link costs 1 and a FastEthernet link costs 10. If you change it on only some routers, path selection becomes inconsistent.
Common mistakes
- Wrong wildcard mask. A wildcard that is too narrow, such as
network 10.0.12.0 0.0.0.0, matches only the exact address 10.0.12.0, which no interface has, so OSPF never starts on G0/0. A wildcard that is too wide, such asnetwork 0.0.0.0 255.255.255.255 area 0, enables OSPF on every interface, including ones you did not intend. Always check "Routing for Networks" inshow ip protocolsand the interface list inshow ip ospf interface. - Area mismatch. One side in area 0 and the other in area 1 means no adjacency.
- Passive interface on a router-to-router link. The subnet is still advertised, but no hellos are sent, so the neighbor never appears.
- Duplicate router IDs. Copying a config from R1 to R2 without changing
router-idcauses unstable or missing adjacencies and duplicate router-id log messages. - Mismatched subnet mask or hello/dead timers on the two ends of an Ethernet link. Both must match.
- Changing the router ID without clearing the process. Run
clear ip ospf processand answer yes so the new RID is used.
Summary
Single-area OSPF needs only a few commands per router: router ospf, a router-id, network statements with correct wildcard masks (or ip ospf 1 area 0 on interfaces), and passive-interface on LANs. Verify in this order: neighbors FULL with show ip ospf neighbor, routes with show ip route ospf, and configuration with show ip protocols. Then prove it with an end-to-end ping.
Related tutorials
- Subnetting Made Simple: /24 to /30 with Worked Examples
- Basic Cisco Router Setup: Hostname, Passwords, Banner and SSH
- Standard vs Extended ACLs on Cisco Routers: Lab with Examples
- DHCP Server on a Cisco Router plus DHCP Relay (ip helper-address)
Sources
- RFC 2328, OSPF Version 2: https://www.rfc-editor.org/rfc/rfc2328
- Cisco IP Routing: OSPF Configuration Guide
- Cisco IOS IP Routing: OSPF Command Reference
No comments