Longest Prefix Match Packet Tracer Lab: Static vs OSPF

Most CCNA and Network+ candidates learn early that on Cisco IOS, a static route has a default Administrative Distance (AD) of 1, while OSPF has a default Administrative Distance of 110. That leads directly to a common routing table exam trap: assuming a static route always beats OSPF. In this hands-on Cisco Packet Tracer lab, you will build a two-server Layer 3 topology where two separate servers hold the exact same IPv4 address (10.1.1.37) in overlapping subnets across isolated Layer 2 broadcast domains. Through four live CLI scenarios, you will prove that Longest Prefix Match (LPM) always wins among installed routes, regardless of Administrative Distance or Metric—and see the exact moment Administrative Distance takes over during route installation.

Download Cisco Packet Tracer Lab Files

Lab Architecture & Why Two Servers Share 10.1.1.37

Normally, putting the same IP address on two devices triggers an IP conflict. In this topology, Server-A and Server-B sit behind separate Layer 3 routers (R2 and R3), keeping their broadcast domains completely isolated:

  • Top Path (Static /16 | AD 1): R1 reaches Server-A (10.1.1.37/16) through R2 using a broad static route for 10.1.0.0/16.
  • Bottom Path (OSPF /24 | AD 110): R1 reaches Server-B (10.1.1.37/24) through R3 using a more specific OSPF Area 0 route for 10.1.1.0/24.

Because both servers respond to 10.1.1.37, every tracert (and optional HTTP check) from PC1 gives unambiguous proof of which path R1 selected.

Cisco Packet Tracer topology with PC1 and R1 connecting to Server-A through static routing on R2 and Server-B through OSPF on R3, both servers using 10.1.1.37.
Two-server Cisco Packet Tracer topology placing Server-A (10.1.1.37/16) and Server-B (10.1.1.37/24) in isolated Layer 3 domains behind R2 and R3.

Required Devices & Cabling

  • Software: Cisco Packet Tracer 9.0.0 (or another compatible version supporting the router models and IOS commands used in this lab)
  • Routers: 3 × Cisco 2911 (R1, R2, R3). Other router models may be used if they provide the required routed Ethernet interfaces. Adjust interface names accordingly.
  • End Devices: 1x PC (PC1), 2x Generic Servers (Server-A, Server-B)
  • Cabling (Copper Straight-Through):
    • PC1 [FastEthernet0] ↔ R1 [GigabitEthernet0/2]
    • R1 [GigabitEthernet0/0] ↔ R2 [GigabitEthernet0/0]
    • R1 [GigabitEthernet0/1] ↔ R3 [GigabitEthernet0/1]
    • R2 [GigabitEthernet0/1] ↔ Server-A [FastEthernet0]
    • R3 [GigabitEthernet0/0] ↔ Server-B [FastEthernet0]

IP Addressing & Subnet Table

DeviceInterfaceIP AddressSubnet MaskDefault GatewayRole / Purpose
PC1Fa0192.168.1.10255.255.255.0192.168.1.1Client testing source
R1G0/2192.168.1.1255.255.255.0N/ALAN gateway for PC1
R1G0/0192.168.12.1255.255.255.0N/AInterconnect to R2 (Static path)
R1G0/1192.168.13.1255.255.255.0N/AInterconnect to R3 (OSPF path)
R2G0/0192.168.12.2255.255.255.0N/ALink to R1
R2G0/110.1.0.1255.255.0.0N/AGateway for Server-A (/16)
Server-AFa010.1.1.37255.255.0.010.1.0.1Destination host in /16
R3G0/1192.168.13.2255.255.255.0N/ALink to R1
R3G0/010.1.1.1255.255.255.0N/AGateway for Server-B (/24)
Server-BFa010.1.1.37255.255.255.010.1.1.1Destination host in /24

Step-by-Step Device Configuration

1. Configure End Devices

On PC1, Server-A, and Server-B, open Desktop → IP Configuration and enter the IPv4 address, subnet mask, and default gateway from the table above.

(Optional Visual Proof) Open Services → HTTP → index.html on both servers and replace the HTML so you can also verify the active path in PC1's web browser at http://10.1.1.37:

Server-A index.html:

<html><body style="font-family:Arial; text-align:center; padding-top:40px; background:#a7f3d0;">
 <h1 style="color:#065f46;">PATH TAKEN: SERVER-A</h1>
 <h2>Static Path (via R2 - 192.168.12.2)</h2>
</body></html>

Server-B index.html:

<html><body style="font-family:Arial; text-align:center; padding-top:40px; background:#c7d2fe;">
 <h1 style="color:#312e81;">PATH TAKEN: SERVER-B</h1>
 <h2>OSPF /24 Path (via R3 - 192.168.13.2)</h2>
</body></html>

2. Configure R1 (Edge Router)

R1 advertises PC1's subnet (192.168.1.0/24) into OSPF Area 0 so R3 automatically learns the return route, and uses a static /16 route pointing to R2.

enable
configure terminal
hostname R1
no ip domain lookup

interface GigabitEthernet0/0
description Link-to-R2-Static
ip address 192.168.12.1 255.255.255.0
no shutdown

interface GigabitEthernet0/1
description Link-to-R3-OSPF
ip address 192.168.13.1 255.255.255.0
no shutdown

interface GigabitEthernet0/2
description LAN-PC1
ip address 192.168.1.1 255.255.255.0
no shutdown
exit

router ospf 1
router-id 1.1.1.1
network 192.168.13.0 0.0.0.255 area 0
network 192.168.1.0 0.0.0.255 area 0
exit

ip route 10.1.0.0 255.255.0.0 192.168.12.2
end
write memory

3. Configure R2 (Static Path Router)

enable
configure terminal
hostname R2
no ip domain lookup

interface GigabitEthernet0/0
description Link-to-R1
ip address 192.168.12.2 255.255.255.0
no shutdown

interface GigabitEthernet0/1
description LAN-Server-A
ip address 10.1.0.1 255.255.0.0
no shutdown
exit

ip route 0.0.0.0 0.0.0.0 192.168.12.1
end
write memory

4. Configure R3 (OSPF Path Router)

enable
configure terminal
hostname R3
no ip domain lookup

interface GigabitEthernet0/1
description Link-to-R1
ip address 192.168.13.2 255.255.255.0
no shutdown

interface GigabitEthernet0/0
description LAN-Server-B
ip address 10.1.1.1 255.255.255.0
no shutdown
exit

router ospf 1
router-id 3.3.3.3
network 192.168.13.0 0.0.0.255 area 0
network 10.1.1.0 0.0.0.255 area 0
end
write memory

Scene 1: Baseline Verification — Longest Prefix Match Overrides AD

In the baseline state, R1 has two valid routes that cover 10.1.1.37.

1. Inspect R1's Routing Table

R1# show ip route
Gateway of last resort is not set

    10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
S     10.1.0.0/16 [1/0] via 192.168.12.2
O     10.1.1.0/24 [110/2] via 192.168.13.2, 00:01:14, GigabitEthernet0/1
    192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C     192.168.1.0/24 is directly connected, GigabitEthernet0/2
L     192.168.1.1/32 is directly connected, GigabitEthernet0/2
    192.168.12.0/24 is variably subnetted, 2 subnets, 2 masks
C     192.168.12.0/24 is directly connected, GigabitEthernet0/0
L     192.168.12.1/32 is directly connected, GigabitEthernet0/0
    192.168.13.0/24 is variably subnetted, 2 subnets, 2 masks
C     192.168.13.0/24 is directly connected, GigabitEthernet0/1
L     192.168.13.1/32 is directly connected, GigabitEthernet0/1
R1 show ip route output displaying static route 10.1.0.0/16 with AD 1 and OSPF route 10.1.1.0/24 with AD 110 installed simultaneously.
R1's baseline routing table holding both the Static /16 route (AD 1) and OSPF /24 route (AD 110) simultaneously.

Notice that both routes coexist in the Routing Information Base (RIB). Because /16 and /24 represent different prefixes, Administrative Distance does not pit them against each other.

2. Query Cisco IOS for 10.1.1.37

R1# show ip route 10.1.1.37
Routing entry for 10.1.1.0/24
 Known via "ospf 1", distance 110, metric 2, type intra area
 Last update from 192.168.13.2 on GigabitEthernet0/1, 00:01:45 ago
 Routing Descriptor Blocks:
 * 192.168.13.2, from 3.3.3.3, 00:01:45 ago, via GigabitEthernet0/1
   Route metric is 2, traffic share count is 1
Cisco IOS destination-specific route lookup for 10.1.1.37 selecting OSPF prefix 10.1.1.0/24 with administrative distance 110 and next hop 192.168.13.2.
Specific prefix query on R1 confirming 10.1.1.37 resolves to the OSPF 10.1.1.0/24 entry rather than the Static /16 route.

Why /24 Beats /16 (Bitwise Breakdown)

To understand R1's forwarding decision, represent 10.1.1.37 in binary (00001010.00000001.00000001.00100101) and compare the matching prefixes from left to right:

Candidate RouteSource & ADBitwise Match Against 10.1.1.37Matching BitsResult
10.1.0.0/16Static (AD 1)00001010.00000001 | xxxxxxxx.xxxxxxxx16 bitsValid backup
10.1.1.0/24OSPF (AD 110)00001010.00000001.00000001 | xxxxxxxx24 bitsWinner (LPM)

24 matching bits beat 16 matching bits. R1 selects the OSPF route immediately—Administrative Distance is never even checked.

3. Verify End-to-End Forwarding from PC1

C:\>tracert 10.1.1.37

Tracing route to 10.1.1.37 over a maximum of 30 hops:

 1  0 ms     0 ms     0 ms     192.168.1.1
 2  0 ms     0 ms     0 ms     192.168.13.2
 3  *        1 ms     0 ms     10.1.1.37

Trace complete.

Note: An initial * timeout on Hop 3 may occur while R3 resolves Server-B's MAC address through ARP. Subsequent traces may resolve all three probes cleanly.

PC1 traceroute to 10.1.1.37 showing hop 1 at 192.168.1.1 and hop 2 at 192.168.13.2 through R3 before reaching Server-B.
Traceroute from PC1 confirming packets traverse R3 (192.168.13.2) along the OSPF path to reach Server-B.

Hop 2 is 192.168.13.2 (R3), confirming traffic lands on Server-B.


Scene 2: Dynamic Failover — Proving the /16 Static Route Was Only Shadowed

Shut down Server-B's LAN interface on R3 to withdraw the /24 OSPF advertisement:

R3# configure terminal
R3(config)# interface GigabitEthernet0/0
R3(config-if)# shutdown
R3(config-if)# end

R3 updates its Router-LSA to remove the advertisement for 10.1.1.0/24 and floods the updated link-state information. After OSPF converges, query R1 again:

R1# show ip route 10.1.1.37
Routing entry for 10.1.0.0/16
 Known via "static", distance 1, metric 0
 Routing Descriptor Blocks:
 * 192.168.12.2
   Route metric is 0, traffic share count is 1
R1 destination lookup after OSPF prefix withdrawal selecting static route 10.1.0.0/16 with administrative distance 1 through next hop 192.168.12.2.
After R3 withdraws 10.1.1.0/24, R1 automatically falls back to the shadowed Static 10.1.0.0/16 route through R2 (192.168.12.2).

Running show ip route ospf on R1 now returns empty. Re-run tracert from PC1:

C:\>tracert 10.1.1.37

Tracing route to 10.1.1.37 over a maximum of 30 hops:

 1  0 ms     0 ms     0 ms     192.168.1.1
 2  0 ms     0 ms     0 ms     192.168.12.2
 3  0 ms     0 ms     0 ms     10.1.1.37

Trace complete.

Hop 2 shifts automatically to 192.168.12.2 (R2), routing traffic cleanly to Server-A without a single configuration change on R1.


Scene 3: The /32 Host Route Override

First, restore R3's link so OSPF re-installs 10.1.1.0/24:

R3# configure terminal
R3(config)# interface GigabitEthernet0/0
R3(config-if)# no shutdown
R3(config-if)# end

Next, inject a /32 static host route (255.255.255.255) on R1 pointing back toward R2:

R1# configure terminal
R1(config)# ip route 10.1.1.37 255.255.255.255 192.168.12.2
R1(config)# end

Inspect R1's routing table with show ip route:

    10.0.0.0/8 is variably subnetted, 3 subnets, 3 masks
S     10.1.0.0/16 [1/0] via 192.168.12.2
O     10.1.1.0/24 [110/2] via 192.168.13.2, 00:00:22, GigabitEthernet0/1
S     10.1.1.37/32 [1/0] via 192.168.12.2

All three overlapping routes now coexist in the RIB. Querying show ip route 10.1.1.37 returns 10.1.1.37/32 via 192.168.12.2, and tracert 10.1.1.37 from PC1 diverts straight back to R2 / Server-A.

Candidate RouteMatching BitsOutcome
10.1.0.0/1616 bitsValid candidate
10.1.1.0/2424 bitsValid candidate
10.1.1.37/3232 bits (100% match)Winner (Longest Prefix Match)
R1 routing table containing three overlapping routes, static 10.1.0.0/16, OSPF 10.1.1.0/24, and static host route 10.1.1.37/32 through R2.
All three prefix lengths coexist in R1's RIB, and the 32-bit host route overrides the healthy OSPF /24 path.

Scene 4: Exact /24 Prefix Tie — Administrative Distance Takes Over

Finally, remove the /32 host route on R1 and add a static /24 route that matches OSPF's exact network prefix and subnet mask:

R1# configure terminal
R1(config)# no ip route 10.1.1.37 255.255.255.255 192.168.12.2
R1(config)# ip route 10.1.1.0 255.255.255.0 192.168.12.2
R1(config)# end

Now run show ip route on R1:

    10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
S     10.1.0.0/16 [1/0] via 192.168.12.2
S     10.1.1.0/24 [1/0] via 192.168.12.2

The OSPF 10.1.1.0/24 entry is gone from the RIB, and show ip route ospf returns no routes.

R1 routing table displaying static 10.1.0.0/16 and static 10.1.1.0/24 through 192.168.12.2 after administrative distance excludes the competing OSPF /24.
On an exact /24 prefix tie, the static 10.1.1.0/24 route (AD 1) replaces the competing OSPF route (AD 110) in R1's routing table.

Proving OSPF Is Still Healthy Behind the Scenes

Did OSPF crash? Verify with two diagnostic commands on R1:

R1# show ip ospf neighbor
R1# show ip ospf database

To inspect the subnet information within R3's Router-LSA, use the following command if supported by your Packet Tracer router:

R1# show ip ospf database router 3.3.3.3

R1 still maintains a FULL adjacency with neighbor 3.3.3.3 on GigabitEthernet0/1, and R3's Router-LSA remains in the OSPF Link-State Database (LSDB), retaining the advertisement for 10.1.1.0/24. Because both sources offered the exact same /24 prefix, Administrative Distance stepped in as the RIB admission filter: Static (AD 1) beat OSPF (AD 110), denying OSPF entry into the routing table. A final tracert 10.1.1.37 from PC1 confirms Hop 2 routes through 192.168.12.2 (R2) to Server-A.


The 3-Tier Router Decision Hierarchy

CCNA The 3-Tier Router Decision Hierarchy

Commit this exact order to memory for CCNA, Network+, and production troubleshooting:

  1. Longest Prefix Match (Forwarding Engine): When forwarding packets, the most specific matching installed prefix (/32 down to /0) wins regardless of routing protocol or Administrative Distance.
  2. Administrative Distance (RIB Admission Filter): Administrative Distance determines the preferred routing source when different sources offer the exact same network prefix and mask. Lower Administrative Distance is preferred.

    Cisco IOS defaults: Connected = 0, Static = 1, eBGP = 20, Internal EIGRP = 90, OSPF = 110, RIP = 120.

  3. Metric (Protocol-Specific Path Selection): When the same routing protocol learns multiple paths to the exact same prefix and mask, it uses its own path-selection rules and metrics to determine the preferred path.

Quick CCNA Self-Check

Suppose R1 simultaneously learns or has configured:

  • Default route: 0.0.0.0/0 (Static, AD 1)
  • Supernet route: 10.1.0.0/16 (Static, AD 1)
  • EIGRP route: 10.1.1.0/24 (Internal EIGRP, AD 90)
  • OSPF route: 10.1.1.0/24 (OSPF, AD 110)

Which /24 route gets installed in the RIB, and which installed route is selected for destination 10.1.1.37?

Reveal Answer

Answer: The EIGRP 10.1.1.0/24 (AD 90) route wins. During route installation, EIGRP (AD 90) beats OSPF (AD 110) for the identical /24 prefix. The static /16 and /0 routes remain installed. During packet forwarding, Longest Prefix Match selects the installed EIGRP /24 route for destination 10.1.1.37.

ComputerNetworkingNotes CCNA Tutorials Longest Prefix Match Packet Tracer Lab: Static vs OSPF

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com