SkarpSkarp

Chapter 14 of 29

Routing Fundamentals: From Default Routes to Static Paths

Follow packets as they cross Layer 3 boundaries, using routing tables, metrics, and static routes to steer traffic toward its destination across multiple networks.

27 min readen

Big Picture: Why Routing Matters (Beyond a Single LAN)

From VLANs to Routing

Earlier, you learned how VLANs and inter-VLAN routing work. Now we zoom out: what happens when traffic must cross multiple Layer 3 networks, not just move between VLANs on one switch?

Layer 2 vs Layer 3

At Layer 2, switches forward frames using MAC addresses. At Layer 3, routers (or multilayer switches) forward packets based on IP addresses and a routing table.

Sources of Routes

Routers learn paths from three main sources: connected routes (directly attached networks), static routes (manually configured), and dynamic routes (learned via routing protocols like OSPFv2).

Focus of This Module

Here we focus on default and static routes and how the longest prefix match rule decides the best path. We also tie this to the host-side default gateway for end-to-end reasoning.

Inside the Routing Table: Prefixes, Masks, and Longest Match

What is a Routing Table?

A routing table is a list of known destination networks and how to reach them. Each entry includes a destination prefix, next hop or interface, administrative distance, metric, and a route source code.

Common Cisco Route Codes

On `show ip route`, you will see codes like C (connected), L (local), S (static), S* (static default candidate), and O (OSPFv2). These tell you how each route was learned.

Longest Prefix Match Rule

When forwarding, the router finds all routes that match the destination IP, then chooses the route with the longest prefix length (most specific). For example, /30 beats /24 beats /16.

AD and Metric After Match

If several routes have the same prefix length, the router uses administrative distance to prefer one routing source over another, and then metric to pick the lowest-cost path.

Walking Through Longest Prefix Match on a Real Table

Sample Routing Table

Look at this trimmed `show ip route` output with connected, OSPF, and a static default: notice 10.0.0.0/24, 172.16.0.0/16, 172.16.10.0/24, and 0.0.0.0/0 via 10.0.0.2.

Destination 172.16.10.25

For 172.16.10.25, routes 172.16.0.0/16, 172.16.10.0/24, and 0.0.0.0/0 all match. The router picks 172.16.10.0/24 because it has the longest prefix (/24).

Destination 8.8.8.8

For 8.8.8.8, none of the specific networks match. Only 0.0.0.0/0 matches, so the router uses the default route (gateway of last resort) via 10.0.0.2.

Key Takeaway

Specific routes always override more general ones. The default route is used only when no other more specific route to the destination exists in the table.

Connected, Static, and Dynamic Routes (and Administrative Distance)

Administrative Distance Basics

Administrative distance (AD) ranks how trustworthy a route source is. Lower AD is preferred. Connected routes have AD 0, static routes AD 1, OSPFv2 AD 110, and RIP AD 120.

Connected Routes

When an interface has an IP and is up, the router adds a C connected route for the subnet and an L local /32 for the interface IP. These directly attached routes are always preferred.

Static Routes

Static routes are configured manually with `ip route`. They default to AD 1 and can point to a next-hop IP or an exit interface. They override dynamic routes with higher AD.

Dynamic Routes

Dynamic protocols like OSPFv2 learn routes automatically. If a static and an OSPFv2 route have the same prefix, the static wins (AD 1 vs 110), assuming both are valid.

Default Gateway vs Default Route: Host and Router Perspectives

Host Default Gateway

A default gateway is the IP of a router interface on the local segment that a host uses to send traffic to remote networks. Example: PC 192.168.1.10 uses 192.168.1.1.

Router Default Route

On a router, a default route is the 0.0.0.0/0 entry telling it where to send packets with no more specific match. Example: `ip route 0.0.0.0 0.0.0.0 203.0.113.1`.

How They Work Together

The host sends unknown destinations to its default gateway. That router then uses its own routing table, including any default route, to forward traffic toward the final destination.

Troubleshooting Tip

When end-to-end connectivity fails, verify both the host’s default gateway setting and the router’s default route. A mistake on either side can break communication.

Lab: Configuring Static Routes and a Default Route on Cisco IOS

Work through this configuration in a small three-router lab (common in CCNA practice):

Topology (IPv4):

  • R1 G0/0: 192.168.10.1/24 (LAN1)
  • R1 G0/1: 10.0.12.1/30 (link to R2)
  • R2 G0/1: 10.0.12.2/30 (link to R1)
  • R2 G0/2: 10.0.23.2/30 (link to R3)
  • R3 G0/2: 10.0.23.3/30 (link to R2)
  • R3 G0/0: 192.168.30.1/24 (LAN3)

Goal:

  • Give R1 a static route to reach 192.168.30.0/24 via R2 and R3.
  • Give R3 a static route to reach 192.168.10.0/24.
  • Configure R2 with a default route pointing to R3.

Example commands:

```text

! On R1

interface g0/0

ip address 192.168.10.1 255.255.255.0

no shutdown

interface g0/1

ip address 10.0.12.1 255.255.255.252

no shutdown

ip route 192.168.30.0 255.255.255.0 10.0.12.2

! On R2

interface g0/1

ip address 10.0.12.2 255.255.255.252

no shutdown

interface g0/2

ip address 10.0.23.2 255.255.255.252

no shutdown

ip route 0.0.0.0 0.0.0.0 10.0.23.3

! On R3

interface g0/2

ip address 10.0.23.3 255.255.255.252

no shutdown

interface g0/0

ip address 192.168.30.1 255.255.255.0

no shutdown

ip route 192.168.10.0 255.255.255.0 10.0.23.2

```

Verification:

```text

R1# show ip route

R1# ping 192.168.30.1

R3# ping 192.168.10.1

R2# show ip route

```

Think through which routers use a specific static route and which use the default route when a host on LAN1 pings a host on LAN3.

Thought Exercise: Predict the Path Step-by-Step

Use this exercise to mentally simulate how routing decisions are made.

Scenario:

  • PC-A: 192.168.10.10/24, default gateway 192.168.10.1 (R1 G0/0)
  • PC-C: 192.168.30.10/24, default gateway 192.168.30.1 (R3 G0/0)
  • Routers R1, R2, R3 are configured as in the previous lab (R1 and R3 have static routes; R2 has a default route to R3).

Task: PC-A pings PC-C.

  1. On PC-A: Is 192.168.30.10 in the same subnet as 192.168.10.10/24? If not, where does PC-A send the packet?
  2. On R1: Which routing table entry matches 192.168.30.10? Is it a connected route, a static route, or the default route?
  3. On R2: When it receives the packet, does it have a specific route to 192.168.30.0/24, or does it rely on its default route? Where does it forward the packet?
  4. On R3: How does R3 know that 192.168.30.10 is directly reachable? Which interface does it use?
  5. On the return path (PC-C to PC-A), which routers use specific static routes, and which use connected routes?

Pause after each question and sketch the path on paper (or in a notes app) before revealing the answers in your head. This kind of mental simulation is exactly what you will need on CCNA troubleshooting questions.

Quick Check: Longest Match and Default Route

Answer this routing decision question.

A router has these IPv4 routes in its table: - C 10.0.0.0/24 is directly connected, G0/0 - S 10.0.0.0/16 [1/0] via 192.0.2.1 - S* 0.0.0.0/0 [1/0] via 198.51.100.1 It receives a packet with destination IP 10.0.0.50. What does the router do?

  1. Use the static 10.0.0.0/16 route via 192.0.2.1 because static beats connected
  2. Drop the packet because there are overlapping routes
  3. Use the connected 10.0.0.0/24 route out G0/0
  4. Use the default route 0.0.0.0/0 via 198.51.100.1
Show Answer

Answer: C) Use the connected 10.0.0.0/24 route out G0/0

The destination 10.0.0.50 matches both 10.0.0.0/24 and 10.0.0.0/16, but the /24 is more specific, so it wins by the longest prefix match rule. The fact that one is static and one is connected only matters if prefix lengths are equal. The router forwards out G0/0 using the connected route.

Quick Check: Default Gateway and Default Route Relationship

Test your understanding of host and router defaults.

A host has IP 192.168.5.10/24 and default gateway 192.168.5.1. The router interface 192.168.5.1/24 is up, but the router has no default route and no specific route to the internet. The host tries to browse a website on the public internet. What happens?

  1. The host cannot send the packet because its default gateway is missing
  2. The host sends the packet to 192.168.5.1, but the router drops it due to no matching route
  3. The router automatically creates a default route for the host
  4. The router forwards the packet using proxy ARP even without a route
Show Answer

Answer: B) The host sends the packet to 192.168.5.1, but the router drops it due to no matching route

The host correctly uses its default gateway 192.168.5.1 and sends the packet to the router. However, the router has neither a specific route nor a default route for the public destination, so it has no matching entry and drops the packet. A valid host default gateway is necessary but not sufficient for end-to-end connectivity.

Key Terms Review: Routing Fundamentals

Flip through these cards to reinforce the core concepts from this module.

Routing table
A data structure on a router that lists known destination networks, their prefix lengths, next-hop IP addresses or outgoing interfaces, administrative distance, metrics, and route sources, used to decide how to forward packets.
Longest prefix match
The rule that when multiple routing table entries match a destination IP, the router selects the route with the most specific prefix (the largest prefix length, such as /30 over /24).
Connected route
A route automatically installed in the routing table for a network that is directly attached to a router interface that is configured with an IP address and is in the up/up state.
Static route
A manually configured route on a router, typically using the `ip route` command, specifying a destination network, mask, and a next-hop IP address or outgoing interface.
Dynamic route
A route that a router learns automatically through a routing protocol such as OSPFv2, which exchanges routing information with neighboring routers.
Default route (IPv4)
A special routing table entry with destination prefix 0.0.0.0/0 that matches all destination addresses and is used when no more specific route exists.
Default gateway (host)
A default gateway is the IP address of a router interface on the local network segment that a host uses to send traffic destined for remote networks.
Administrative distance (AD)
A value that rates the trustworthiness of a route’s source; lower AD is preferred. Examples: 0 for connected, 1 for static, 110 for OSPFv2.
Gateway of last resort
Cisco IOS terminology for the next-hop router used by the default route (0.0.0.0/0) when forwarding packets with no more specific match.
Candidate default route (S*)
A static route flagged with `*` in `show ip route` that can serve as the default route, typically configured as `ip route 0.0.0.0 0.0.0.0 <next-hop>`.

Common Static Routing Pitfalls and How to Spot Them

Return Path Missing

A very common issue: you add a static route in one direction but forget the route back. Pings seem one-way. Always ensure every network has a path back to the source network.

Bad Next-Hop Choice

Static routes fail if the next-hop IP is wrong or unreachable. Always ensure the next hop is on a directly connected network and can be pinged from the router.

Default Route to a Host

Do not point a default route to an end host. It must point to an upstream router that can actually forward traffic further, not to a PC on the LAN.

Static vs Dynamic Overlap

Static routes override dynamic ones with the same prefix because of lower AD. This can unintentionally shadow OSPFv2 routes, so check for overlapping entries in `show ip route`.

Key Terms

OSPFv2
Open Shortest Path First version 2 (OSPFv2) is a link-state interior gateway protocol used to exchange IPv4 routing information within a single autonomous system.
Static route
A manually configured route on a router, typically using the `ip route` command, specifying a destination network, mask, and a next-hop IP address or outgoing interface.
Default route
A special routing table entry with destination prefix 0.0.0.0/0 that matches all destinations and is used when no more specific route exists.
Dynamic route
A route that a router learns automatically through a routing protocol such as OSPFv2, which exchanges routing information with neighboring routers.
Routing table
A data structure on a router that lists known destination networks, their prefix lengths, next-hop IP addresses or outgoing interfaces, administrative distance, metrics, and route sources, used to decide how to forward packets.
Connected route
A route automatically installed in the routing table for a network that is directly attached to a router interface that is configured with an IP address and is in the up/up state.
default gateway
A default gateway is the IP address of a router interface on the local network segment that a host uses to send traffic destined for remote networks.
Longest prefix match
The rule that when multiple routing table entries match a destination IP, the router selects the route with the most specific prefix (the largest prefix length).
Gateway of last resort
Cisco IOS terminology for the next-hop router used by the default route when forwarding packets with no more specific match.
Administrative distance
A value that rates the trustworthiness of a route’s source; lower administrative distance is preferred (for example, 0 for connected, 1 for static, 110 for OSPFv2).

Finished reading?

Test your understanding with a custom practice exam on this chapter.

Test yourself