Menu
Coddy logo textTech

Routing Tables

Lesson 14 of 32 in Coddy's The OSI Model course.

A router picks the next hop by consulting its routing table: a list of "for this address range, send it that way" rules. When several rules match, the most specific one wins: the longest prefix.

Consider a router with three routes:

  • 0.0.0.0/0 via gateway A (the default: matches everything)
  • 10.0.0.0/8 via gateway B
  • 10.1.0.0/16 via gateway C

A packet to 10.1.2.3 matches all three, but /16 is the longest prefix, so it goes via C. This rule, longest prefix wins, is the entire logic of internet routing.

challenge icon

Challenge

Easy

Using the routing table from the theory, print the gateway letter each packet leaves through, one per line, in this order:

  1. 10.1.2.3
  2. 10.9.9.9
  3. 8.8.8.8

Expected output:

C
B
A

Try it yourself

Terminal

All lessons in The OSI Model

Practice on your own: Terminal playground