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/0via gateway A (the default: matches everything)10.0.0.0/8via gateway B10.1.0.0/16via 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
EasyUsing the routing table from the theory, print the gateway letter each packet leaves through, one per line, in this order:
10.1.2.310.9.9.98.8.8.8
Expected output:
C
B
ATry it yourself
All lessons in The OSI Model
Practice on your own: Terminal playground