xkonekt
Language: EN
  • English
  • Türkçe
  • Español, Coming soon
  • Português, Coming soon
  • Deutsch, Coming soon
  • Français, Coming soon

IP routing · Introduction · Module 2

Longest prefix match and the default route: when routes overlap, or none fits

Show topologyHide topology
R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24

Interfaces and addresses · Et0/0 = Ethernet0/0. R2, R3 and R4 each also hold one more network: 10.2.1.0/24, 198.51.100.0/24 and 10.2.3.0/24.

  • 10.1.1.0/24R1 Et0/0 10.1.1.1H1 eth0 10.1.1.10
  • 10.0.12.0/24R1 Et0/1 10.0.12.1R2 Et0/0 10.0.12.2
  • 10.0.14.0/24R1 Et0/2 10.0.14.1R4 Et0/0 10.0.14.4
  • 203.0.113.0/24R1 Et0/3 203.0.113.2R3 Et0/0 203.0.113.1
Topology · R1, the office router, joins four networks: H1’s office network and its links to R2 (HQ), R4 (the branch) and R3 (the provider).

Five device icons joined by four plain cables, in a cross with R1, the office router, at the center. Above it, R3, the provider router, holding 198.51.100.1/24, on a cable labeled 203.0.113.0/24. Left of it, R2, the HQ router, holding 10.2.1.2/24, on a cable labeled 10.0.12.0/24. Right of it, R4, the branch router, holding 10.2.3.4/24, on a cable labeled 10.0.14.0/24. Under it, H1, the office host, a laptop, on a cable labeled 10.1.1.0/24. The list under the drawing gives the interface and the address at each end of each cable.

What longest match is

Overlapping routes and the default

When two routes match

R1 now has a route, 10.2.0.0/16, to R2 for every address that starts 10.2, the branch address 10.2.3.4 too. So why does R1 send a packet for 10.2.3.4 to R4?

Because another of its routes, a longer one, covers that address as well: the branch route 10.2.3.0/24 to R4. A third route, 0.0.0.0/0, leads to the provider router R3.

R1’s three static (typed-in) routes now
RouteSends toCovers
10.2.0.0/16R2 (HQ)every address that starts 10.2
10.2.3.0/24R4 (branch)every address that starts 10.2.3
0.0.0.0/0R3 (provider)every address

You can test both routes against 10.2.3.4 yourself. A route matches when the destination’s first bits, as many as the prefix length, equal the route’s prefix. For 10.2.0.0/16 those are the first two numbers, 10.2, and for 10.2.3.0/24 the first three, 10.2.3, so both match.

Why the longer one? A longer prefix fixes more bits of the address, so it says more exactly where the destination is. Routers therefore follow longest prefix match, the rule that the router uses the matching route with the longest prefix.

So R1 uses 10.2.3.0/24 and sends the packet to R4. Routers on the internet forward on this longest-match basis too.

The /16 is the larger block, but that gives it no advantage. The rule compares prefix lengths, not how many addresses a route covers.

Each route covers a range of addresses, and here the ranges sit one inside the other (Figure 2.1). Each address takes the route of the innermost range that holds it.

0.0.0.0/0every address · R310.2.0.0/16HQ block · R210.2.3.0/24branch · R4198.51.100.1uses /010.2.3.4uses /2410.2.1.2uses /16not to scale
Figure 2.1 · Each address uses the longest route that covers it: 10.2.3.4 the /24, 10.2.1.2 the /16, 198.51.100.1 only the /0.

Three rows, one per route, each with its prefix at the left and an outlined bar at the right. Top row: 0.0.0.0/0, every address, toward R3, the widest bar. Middle row: 10.2.0.0/16, the HQ block, toward R2, a shorter bar inside the first. Bottom row: 10.2.3.0/24, the branch, toward R4, the shortest bar, inside the second. Three vertical lines cross the bars, one per address. The line for 198.51.100.1 crosses only the top bar, with a dot on it: it uses the /0. The line for 10.2.1.2 crosses the top and middle bars, with a dot on the middle one: it uses the /16. The line for 10.2.3.4 crosses all three, with a highlighted dot on the bottom one: it uses the /24. A note says the drawing is not to scale.

R1 has the routes 10.2.0.0/16 via R2 and 10.2.3.0/24 via R4. Where does a packet for 10.2.1.2 go?

Two routes with the same prefix, one typed in and one learned another way, tie on length; other rules then choose.

The default route

No route in R1’s table names most of the networks on the internet. What does R1 do with a packet for one of them?

R1 sends it by a route that matches any address, the default route 0.0.0.0/0. Its prefix length is 0, so no bit has to be equal and every address matches.

Any other route that matches is longer than 0, so under longest match it beats the default. The default route is used only when nothing longer matches. On R1 it sends those packets to the provider router R3.

A route that matches every address might seem to send all traffic to R3. It carries only what nothing longer matches, so a packet for the branch still goes to R4 by the /24.

R1’s table prints the default route’s next hop on its own line, ahead of the route lines, as the gateway of last resort, 203.0.113.1, R3’s address on their shared link.

What if there is no default route and nothing else matches? Then the router discards the packet. If another device sent the packet, the router must tell it that the address cannot be reached, though it may limit how often.

A host needs a way out of its own network too. Its default gateway is the router address it sends packets for other networks to, and H1’s is R1, 10.1.1.1. The computer you are reading this on most likely has one as well.

H1 sends R1 only the packets that leave its own network. A packet for an address in its own network, 10.1.1.0/24, goes straight to that device.

One packet from H1 to the internet uses both H1’s default gateway and R1’s default route (Figure 2.2).

R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office hostdefault gateway:R1, 10.1.1.1default route0.0.0.0/0
Figure 2.2 · H1 sends everything for other networks to R1, its default gateway; R1 sends what no route with a longer prefix matches to R3.

The network: R1 at the center of a cross, R3 above it, R2 left of it, R4 right of it and H1 under it. A short arrow beside the cable from H1 points up toward R1, with the note “default gateway: R1, 10.1.1.1”. A highlighted short arrow left of the cable from R1 points up toward R3, with the note “default route 0.0.0.0/0” left of it. The cables to R2 and R4 have no arrow.

Key idea

When routes overlap, the longest matching prefix wins. The default route 0.0.0.0/0 matches every address but has the shortest prefix, so it wins only when nothing else matches; with no match at all, the packet is dropped.

Which packets can R1’s default route carry?

How it works

R1 looks up three addresses

R1 sends one test packet to each of three addresses. Which route does each one take?

Two of them match more than one route, and each takes the longest one that matches (Figure 2.3). How can you see which way each packet left? With debug ip packet on, R1 logs each packet that starts or ends at R1, and show logging | include IP: prints those lines.

Step 1 of 6

R1’s typed-inroutes/16 → R2/24 → R4/0 → R3R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24

R1 holds three typed-in routes that overlap: 10.2.0.0/16 to R2, 10.2.3.0/24 to R4 and 0.0.0.0/0 to R3.

Step 2 of 6

to 10.2.1.2matches /16 and /0uses /16 → R2R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24/16

10.2.1.2 matches 10.2.0.0/16 and 0.0.0.0/0. The /16 is longer, so R1 sends the packet out of Ethernet0/1 to R2.

Next, 10.2.3.4. It matches all three routes. Which one does R1 use?

  • S 10.2.0.0/16 [1/0] via 10.0.12.2, Ethernet0/1.: It matches, but its prefix is shorter: 16 bits against 24. Covering more addresses is not what decides; the longest matching prefix is.
  • S* 0.0.0.0/0 [1/0] via 203.0.113.1, Ethernet0/3.: With prefix length 0, the default is the shortest of the three matches and loses to both others.
  • The first matching line printed in the table.: R1 compares the prefix lengths of all the routes that match; where a line is printed plays no part.
  • S 10.2.3.0/24 [1/0] via 10.0.14.4, Ethernet0/2. (Correct): The /24 fixes 24 bits, more than the /16 or the /0, so it is the longest match. Its next hop is 10.0.14.4, R4, out of Ethernet0/2.

Step 3 of 6

to 10.2.3.4matches /24, /16, /0uses /24 → R4R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24/16/24

10.2.3.4 matches all three routes. The /24 is the longest, so R1 sends the packet out of Ethernet0/2 to R4.

Step 4 of 6

to 198.51.100.1matches /0 onlyuses /0 → R3R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24/16/24/0

198.51.100.1 matches only the default route. R1 sends the packet out of Ethernet0/3 to 203.0.113.1, its gateway of last resort.

Step 5 of 6

to 198.51.100.1no /0 routematches nothingR1 drops itR3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24/16/24

Without the default route, 198.51.100.1 matches nothing, so R1 drops the packet. R1’s debug line for it ends with unroutable.

Step 6 of 6

threeaddresseslongest match winsno match: dropR3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24/16/24/0

R1 uses the longest match, falls back on the default route only when nothing longer matches, and drops a packet that matches nothing.

Step 1 of 6

A strip at the top holds two chips: the destination, and the routes that match. Under it, the network: R1 at the center, R3 above it, R2 left, R4 right and H1 under it. Step 1: the chips read “R1’s typed-in routes” and “/16 → R2 · /24 → R4 · /0 → R3”. Step 2: “to 10.2.1.2”, “matches /16 and /0, uses /16 → R2”, and a short arrow beside the cable to R2, pointing to R2, noted /16. Step 3: “to 10.2.3.4”, “matches /24, /16, /0, uses /24 → R4”, and a short arrow beside the cable to R4, pointing to R4, noted /24; the /16 arrow stays, in gray. Step 4: “to 198.51.100.1”, “matches /0 only, uses /0 → R3”, and a short arrow left of the cable to R3, pointing up to R3, noted /0; the /16 and /24 arrows stay, in gray. Step 5: “to 198.51.100.1, no /0 route”, “matches nothing, R1 drops it”, and a cross beside the cable to R3, left of it at R1’s end, just above R1, in place of the /0 arrow; the /16 and /24 arrows stay, in gray. In step 6 the three arrows keep their notes, and the chips read “three addresses” and “longest match wins; no match: drop”.

Figure 2.3 · Of the routes that match, R1 uses the longest; the default only when nothing longer matches; with no match, it drops the packet.R1 holds three typed-in routes that overlap: 10.2.0.0/16 to R2, 10.2.3.0/24 to R4 and 0.0.0.0/0 to R3.Debug line at this stepIP: tableid=0, s=10.0.12.1 (local), d=10.2.1.2 (Ethernet0/1) nexthop=10.0.12.2, routed via FIB10.2.1.2 matches 10.2.0.0/16 and 0.0.0.0/0. The /16 is longer, so R1 sends the packet out of Ethernet0/1 to R2.Debug line at this stepIP: tableid=0, s=10.0.14.1 (local), d=10.2.3.4 (Ethernet0/2) nexthop=10.0.14.4, routed via FIB10.2.3.4 matches all three routes. The /24 is the longest, so R1 sends the packet out of Ethernet0/2 to R4.Debug line at this stepIP: tableid=0, s=203.0.113.2 (local), d=198.51.100.1 (Ethernet0/3) nexthop=203.0.113.1, routed via FIB198.51.100.1 matches only the default route. R1 sends the packet out of Ethernet0/3 to 203.0.113.1, its gateway of last resort.Debug line at this stepIP: s=10.0.12.1 (local), d=198.51.100.1 (nil), len 100, unroutableWithout the default route, 198.51.100.1 matches nothing, so R1 drops the packet. R1’s debug line for it ends with unroutable.R1 uses the longest match, falls back on the default route only when nothing longer matches, and drops a packet that matches nothing.

On R1, the lines debug ip packet printed for the three test packets:

A sent packet’s first line has the destination after d=, the interface in the parentheses after it and the next hop after nexthop=.

Lines appear as you step through.

Output · IOS XE 17.18.2
R1#show logging | include IP:2IP: tableid=0, s=10.0.12.1 (local), d=10.2.1.2 (Ethernet0/1) nexthop=10.0.12.2, routed via FIB… 6 more lines (see Full output)3IP: tableid=0, s=10.0.14.1 (local), d=10.2.3.4 (Ethernet0/2) nexthop=10.0.14.4, routed via FIB… 6 more lines (see Full output)4IP: tableid=0, s=203.0.113.2 (local), d=198.51.100.1 (Ethernet0/3) nexthop=203.0.113.1, routed via FIB… 6 more lines (see Full output)
Full output · 21 lines
R1#show logging | include IP:IP: tableid=0, s=10.0.12.1 (local), d=10.2.1.2 (Ethernet0/1) nexthop=10.0.12.2, routed via FIBIP: s=10.0.12.1 (local), d=10.2.1.2 (Ethernet0/1), len 100, sendingIP: s=10.0.12.1 (local), d=10.2.1.2 (Ethernet0/1), len 100, sending full packetIP: s=10.2.1.2 (Ethernet0/1), d=10.0.12.1 (nil), len 100, input feature, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEIP: s=10.2.1.2 (Ethernet0/1), d=10.0.12.1 (nil), len 100, rcvd 2IP: s=10.2.1.2 (Ethernet0/1), d=10.0.12.1 (nil), len 100, stop process pak for forus packetIP: tableid=0, s=10.2.1.2 (Ethernet0/1), d=10.0.12.1 (Ethernet0/1) nexthop=10.0.12.1, routed via RIBIP: tableid=0, s=10.0.14.1 (local), d=10.2.3.4 (Ethernet0/2) nexthop=10.0.14.4, routed via FIBIP: s=10.0.14.1 (local), d=10.2.3.4 (Ethernet0/2), len 100, sendingIP: s=10.0.14.1 (local), d=10.2.3.4 (Ethernet0/2), len 100, sending full packetIP: s=10.2.3.4 (Ethernet0/2), d=10.0.14.1 (nil), len 100, input feature, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEIP: s=10.2.3.4 (Ethernet0/2), d=10.0.14.1 (nil), len 100, rcvd 2IP: s=10.2.3.4 (Ethernet0/2), d=10.0.14.1 (nil), len 100, stop process pak for forus packetIP: tableid=0, s=10.2.3.4 (Ethernet0/2), d=10.0.14.1 (Ethernet0/2) nexthop=10.0.14.1, routed via RIBIP: tableid=0, s=203.0.113.2 (local), d=198.51.100.1 (Ethernet0/3) nexthop=203.0.113.1, routed via FIBIP: s=203.0.113.2 (local), d=198.51.100.1 (Ethernet0/3), len 100, sendingIP: s=203.0.113.2 (local), d=198.51.100.1 (Ethernet0/3), len 100, sending full packetIP: s=198.51.100.1 (Ethernet0/3), d=203.0.113.2 (nil), len 100, input feature, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEIP: s=198.51.100.1 (Ethernet0/3), d=203.0.113.2 (nil), len 100, rcvd 2IP: s=198.51.100.1 (Ethernet0/3), d=203.0.113.2 (nil), len 100, stop process pak for forus packetIP: tableid=0, s=198.51.100.1 (Ethernet0/3), d=203.0.113.2 (Ethernet0/3) nexthop=203.0.113.2, routed via RIB

Impact A debug adds work for the router. Keep it on for a few seconds only, then turn it off again.

By longest match, the packet for 10.2.1.2 left through Ethernet0/1 to next hop 10.0.12.2, the one for 10.2.3.4 through Ethernet0/2 to 10.0.14.4, and the one for 198.51.100.1 through Ethernet0/3 to 203.0.113.1.

R1 compares all the routes that match before it chooses, so a route’s place in the table plays no part.

On R1, with the default route removed, the line debug ip packet printed for one test packet to 198.51.100.1:

Without the default route, R1 found no route for 198.51.100.1 and sent nothing.

Output · IOS XE 17.18.2
R1#show logging | include IP:1IP: s=10.0.12.1 (local), d=198.51.100.1 (nil), len 100, unroutable
  1. After the d= address the parentheses hold (nil) instead of an interface, and the line ends with unroutable: no route matched.

A router discards a packet that no route matches. It does not send copies of it out of all its interfaces instead.

Why did 10.2.3.4 go to R4, although 10.2.0.0/16 via R2 also matches it?

Key idea

R1 uses the longest of all matching routes, not the first match it finds.

Verify

Read routes that overlap

Where does R1’s table show the default route, and which line serves 10.2.3.4?

show ip route prints the default route in two places: a line above the routes, and a route line with a star.

On R1, from the whole table:

The legend explains the star, and two lines show the default route.

Output · IOS XE 17.18.2
R1#show ip route… 6 more lines (see Full output)1       ia - IS-IS inter area, * - candidate default, U - per-user static route… 6 more lines (see Full output)2Gateway of last resort is 203.0.113.1 to network 0.0.0.0 3S*    0.0.0.0/0 [1/0] via 203.0.113.1, Ethernet0/3… 12 more lines (see Full output)
  1. * - candidate default: the star marks the default route.
  2. The gateway of last resort: 203.0.113.1, the next hop of the default route. “network 0.0.0.0” is the route it belongs to.
  3. S*: a typed-in route, with the star. It is 0.0.0.0/0, out of Ethernet0/3 to 203.0.113.1.
Full output · 28 lines
R1#show ip routeCodes: 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, m - OMP       n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2       ia - IS-IS inter area, * - candidate default, U - per-user static route       H - NHRP, G - NHRP registered, g - NHRP registration summary       o - ODR, P - periodic downloaded static route, l - LISP       a - application route       + - replicated route, % - next hop override, p - overrides from PfR       & - replicated local route overrides by connected Gateway of last resort is 203.0.113.1 to network 0.0.0.0 S*    0.0.0.0/0 [1/0] via 203.0.113.1, Ethernet0/3      10.0.0.0/8 is variably subnetted, 8 subnets, 3 masksC        10.0.12.0/24 is directly connected, Ethernet0/1L        10.0.12.1/32 is directly connected, Ethernet0/1C        10.0.14.0/24 is directly connected, Ethernet0/2L        10.0.14.1/32 is directly connected, Ethernet0/2C        10.1.1.0/24 is directly connected, Ethernet0/0L        10.1.1.1/32 is directly connected, Ethernet0/0S        10.2.0.0/16 [1/0] via 10.0.12.2, Ethernet0/1S        10.2.3.0/24 [1/0] via 10.0.14.4, Ethernet0/2      203.0.113.0/24 is variably subnetted, 2 subnets, 2 masksC        203.0.113.0/24 is directly connected, Ethernet0/3L        203.0.113.2/32 is directly connected, Ethernet0/3

On R1, the “Gateway of last resort” line repeats the default route’s next hop; R1 has no separate setting for it.

Each route line comes from one of R1’s connected interfaces or from a typed-in route (Figure 2.4).

R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office hostEt0/0C + LEt0/1C + L + SEt0/2C + L + SEt0/3C + L + S*
Figure 2.4 · R1’s four Ethernet interfaces give four C and four L lines, and its three typed-in routes three S lines, eleven in all.

The network, with two values beside each cable, one on each side of it: R1’s interface on that cable and the route lines it carries. They sit at R1’s end of the cables to H1, R2 and R4, and half-way along the cable to R3, above R1’s name. “Et0/0” and “C + L” on the cable to H1, “Et0/1” and “C + L + S” on the cable to R2, “Et0/2” and “C + L + S” on the cable to R4, and “Et0/3” and “C + L + S*” on the cable to R3. The S on the cable to R2 is the /16, the S on the cable to R4 the /24, and S* is the default route.

To leave the legend out, add | begin Gateway, and R1 starts at the line that holds “Gateway”.

On R1, from Gateway on:

Tap a line, or “Not in the output”, then submit.

Find the line R1 uses for a packet to 10.2.3.4.

Output · IOS XE 17.18.2
R1#show ip route | begin Gateway

R1 has three overlapping typed-in routes and C and L lines for its four own networks.

  1. S*: the default route, through R3. Printed first, yet the shortest prefix of all.
  2. A heading, not a route: it groups the lines under it.
  3. S: the whole 10.2.0.0/16 block, next hop 10.0.12.2, R2.
  4. S: the branch network 10.2.3.0/24, next hop 10.0.14.4, R4. The longest match for 10.2.3.4.

Ask R1 about the branch address itself, and it names the same route.

On R1, asking for 10.2.3.4:

R1 names one route for 10.2.3.4, the /24.

Output · IOS XE 17.18.2
R1#show ip route 10.2.3.41Routing entry for 10.2.3.0/24  Known via "static", distance 1, metric 0  Routing Descriptor Blocks:2  * 10.0.14.4, via Ethernet0/2      Route metric is 0, traffic share count is 1
  1. The longest match: 10.2.3.0/24, not the /16 and not the default.
  2. The next hop, 10.0.14.4, and the interface, Ethernet0/2. This * marks the next-hop line, not the default route.

You can ask about any address. For 10.2.1.2 it names the /16. For 198.51.100.1, which only the default covers, it prints “% Network not in table”, yet R1 still uses the default route; read “Gateway of last resort” instead.

Key idea

“Gateway of last resort” and the S* line show the default route. For any address, the line R1 uses is the matching one with the longest prefix, whatever its place in the table.

In R1’s routes, which line serves a packet for 10.2.200.1?

Troubleshoot

No route, or the wrong one

A route goes missing from R1’s table. Are its packets then dropped, or sent the wrong way?

It depends on whether a shorter route still matches. Either way, a test from R1 fails in this network. With ping, R1 by default sends five test packets to an address; each ! is a reply, and each . a packet that got no reply in time.

Case 1 of 2.R1 gets no answer from the internet

  1. Case 1 · Symptom

    R1 tests 198.51.100.1, an address on the internet side, and gets no answer.

    Output · IOS XE 17.18.2
    R1#ping 198.51.100.1Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 198.51.100.1, timeout is 2 seconds:1.....2Success rate is 0 percent (0/5)
    1. Five dots, one for each test packet.
    2. Success rate is 0 percent: not one answer came back.
  2. Case 1 · Command

    Does R1 still have a default route?

  3. Case 1 · Output

    On R1:

    Output · IOS XE 17.18.2
    R1#show ip route | begin Gateway1Gateway of last resort is not set       10.0.0.0/8 is variably subnetted, 8 subnets, 3 masksC        10.0.12.0/24 is directly connected, Ethernet0/1L        10.0.12.1/32 is directly connected, Ethernet0/1C        10.0.14.0/24 is directly connected, Ethernet0/2L        10.0.14.1/32 is directly connected, Ethernet0/2C        10.1.1.0/24 is directly connected, Ethernet0/0L        10.1.1.1/32 is directly connected, Ethernet0/02S        10.2.0.0/16 [1/0] via 10.0.12.2, Ethernet0/12S        10.2.3.0/24 [1/0] via 10.0.14.4, Ethernet0/2      203.0.113.0/24 is variably subnetted, 2 subnets, 2 masksC        203.0.113.0/24 is directly connected, Ethernet0/3L        203.0.113.2/32 is directly connected, Ethernet0/3
    1. Key line Gateway of last resort is not set: no default route. No S* line is printed either.
    2. The two S lines left cover only addresses that start 10.2. No line covers 198.51.100.1.
  4. Case 1 · How far it reaches

    R1 tests the branch, which has a route of its own, the /24.

    On R1, a test of the branch, 10.2.3.4:

    Output · IOS XE 17.18.2
    R1#ping 10.2.3.4Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.2.3.4, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent: the branch answers.
  5. Case 1 · What it means

    R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerno route for198.51.100.1
    Figure 2.5 · Case 1 · Without a default route nothing matches 198.51.100.1: R1 drops it.

    R1 with R3 above it and R2 left of it, each joined to R1 by one cable. Right of the cable to R3 the highlighted note “no route for 198.51.100.1”, and under it a cross beside the cable, just above R1.

    • No route in R1’s table matches 198.51.100.1: the default route was the only one that did.
    • With nothing to match, R1 drops the packets.
    • Addresses that another route matches still work: the branch answered.
  6. Case 1 · Fix

    Put the default route back.

    On R1, the lines that change it:

    Output · IOS XE 17.18.2
    R1#configure terminalEnter configuration commands, one per line.  End with CNTL/Z.1R1(config)#ip route 0.0.0.0 0.0.0.0 Ethernet0/3 203.0.113.1R1(config)#end
    1. The default route: address and mask 0.0.0.0 0.0.0.0, which is 0.0.0.0/0, out of Ethernet0/3 to next hop 203.0.113.1.

    Impact A wrong default route sends every packet that no other route matches the wrong way.

  7. Case 1 · Proof

    R1 tests 198.51.100.1 again.

    Output · IOS XE 17.18.2
    R1#ping 198.51.100.1Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 198.51.100.1, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent: the internet side answers again.

End of case 1. Solved: The default route is back, through R3 again.

Case 2 of 2.R1 gets no answer from the branch

  1. Case 2 · Symptom

    R1 tests the branch, 10.2.3.4, and gets no answer.

    Output · IOS XE 17.18.2
    R1#ping 10.2.3.4Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.2.3.4, timeout is 2 seconds:1.U.U.2Success rate is 0 percent (0/5)
    1. Each U means a router on the way answered that it cannot reach the address. Each dot means no answer came in time.
    2. Success rate is 0 percent: no test reached the branch.
  2. Case 2 · Command

    Which route does R1 use for 10.2.3.4 now?

  3. Case 2 · Output

    On R1:

    Output · IOS XE 17.18.2
    R1#show ip route 10.2.3.41Routing entry for 10.2.0.0/16  Known via "static", distance 1, metric 0  Routing Descriptor Blocks:2  * 10.0.12.2, via Ethernet0/1      Route metric is 0, traffic share count is 1
    1. Key line The /16, 10.2.0.0/16, not the branch /24.
    2. So the next hop is 10.0.12.2, R2, out of Ethernet0/1: the way to HQ.
  4. Case 2 · How far it reaches

    R1 tests HQ.

    On R1, a test of HQ, 10.2.1.2:

    Output · IOS XE 17.18.2
    R1#ping 10.2.1.2Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.2.1.2, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent: HQ answers.
  5. Case 2 · What it means

    R3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office hostto 10.2.3.4 by the /16R2 has no route for itno /24route
    Figure 2.6 · Case 2 · Without the /24, the /16 sends branch packets to R2, which has no route for them.

    The whole network: R1 at the center, R3 above it, R2 left, the branch router R4 right and H1 under it. A highlighted short arrow beside the cable to R2 points from R1 to R2, with the highlighted notes “to 10.2.3.4 by the /16” and “R2 has no route for it” under it. The cable from R1 to R4, the way the branch packets should take, has no arrow, only the note “no /24 route” at R1’s end.

    • The /24 route to R4 is gone, so the longest match for 10.2.3.4 is now the /16: R1 sends branch packets to R2.
    • R2 has one typed-in route, back to the office network, and nothing for 10.2.3.0/24. With no route for the address, R2 answers that it cannot reach it: those are the U marks.
    • HQ still answers: only the addresses the missing /24 covered go the wrong way.
  6. Case 2 · Fix

    Put the branch route back.

    On R1, the lines that change it:

    Output · IOS XE 17.18.2
    R1#configure terminalEnter configuration commands, one per line.  End with CNTL/Z.1R1(config)#ip route 10.2.3.0 255.255.255.0 Ethernet0/2 10.0.14.4R1(config)#end
    1. The branch route: 10.2.3.0/24 (mask 255.255.255.0), out of Ethernet0/2 to next hop 10.0.14.4.

    Impact A route added or removed changes at once where R1 sends its packets.

  7. Case 2 · Proof

    R1 tests the branch again.

    Output · IOS XE 17.18.2
    R1#ping 10.2.3.4Type escape sequence to abort.Sending 5, 100-byte ICMP Echos to 10.2.3.4, timeout is 2 seconds:!!!!!1Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
    1. Success rate is 100 percent: the branch answers again.

End of case 2. Solved: The /24 is back as the longest match for the branch.

Both cases

Key idea

No match means a drop. When a longer route is missing but a shorter one still matches, the shorter route carries the traffic, possibly the wrong way.

R1 loses its 10.2.0.0/16 route; the /24 and the default route stay. Where does a packet for 10.2.1.2 go?

Check

R1’s table says Gateway of last resort is 203.0.113.1 to network 0.0.0.0. What does that tell you?
A router has three routes: 10.0.0.0/8 via A, 10.144.0.0/16 via B and 10.144.2.0/24 via C. Where does it send a packet for 10.144.2.5?

On R1:

Tap a line, or “Not in the output”, then submit.

Find the line R1 uses for a packet to 10.2.3.4.

Output · IOS XE 17.18.2
R1#show ip route | begin Gateway
With R1’s three typed-in routes, 10.2.0.0/16 via R2, 10.2.3.0/24 via R4 and 0.0.0.0/0 via R3, where does a packet for 10.2.9.9 go?
R1’s default route is removed; the /16 and the /24 stay. Which of 10.2.1.2, 10.2.3.4 and 198.51.100.1 still answer?

Summary

threeaddresseslongest match winsno match: dropR3provider routerhas 198.51.100.1/24R2HQ routerhas 10.2.1.2/24R1office routerR4branch routerhas 10.2.3.4/24H1office host10.1.1.0/2410.0.12.0/2410.0.14.0/24203.0.113.0/24/16/24/0
Figure 2.3, recap · R1 uses the longest match, falls back on the default route only when nothing longer matches, and drops a packet that matches nothing.

The network under a strip of two chips that read “three addresses” and “longest match wins; no match: drop”. Three short arrows beside the cables point away from R1: left to R2 noted /16, right to R4 noted /24, and, left of the cable to R3, up to R3 noted /0.

  • When several routes match a destination, the router uses the one with the longest prefix, whatever its place in the table.
  • The default route 0.0.0.0/0 is used only when nothing longer matches. A host sends packets for other networks to its default gateway.
  • With no match at all, the router drops the packet.
  • show ip route 10.2.3.4 names the route R1 uses for the branch address, its longest match, the /24. For an address only the default route covers, read “Gateway of last resort”, the default route’s next hop.
  • A missing route may drop a packet or send it the wrong way by the next-longest match.