Routing Table Analysis
In previous practical classes you added routes manually (static) and with protocols (RIP, OSPF, BGP). Today is “detective” day: you read a ready-made routing table and work out which way a packet will go. You will analyze the output of route print on Windows, ip route on Linux and show ip route on Cisco, apply the longest prefix rule, administrative distance and metric in practice, and automate all of this in Python.
Lesson goals and plan
By the end of the lesson you will…
- you can read every column and code in the output of show ip route, route print and ip route
- you can determine a packet’s next hop with the longest prefix match rule
- you can choose the best route among routes to the same network from several sources by administrative distance (AD) and metric
- you can explain the role of the default route (0.0.0.0/0) and directly connected (C, L) routes
- you can find errors in a routing table (a missing route, a wrong next-hop, a loop)
- you can write Python programs that analyze a table (parser, LPM, AD selection)
Plan (according to the syllabus)
- Routing Table Analysis
Memorize the rule: first the longest prefix, then the smallest AD, then the smallest metric. AD and metric are compared only between routes with the same prefix — a /24 always beats a /16, whatever the AD :ik-quti:
The router has two routes: 0.0.0.0/0 (everywhere) and 10.1.1.0/24. Both “match” 10.1.1.5. The router chooses the most specific route — the one with the longest prefix. Just like in the metro: a precise sign such as “Novza station — exit 2” beats a general sign like “Chilonzor direction”. Today you will learn to apply this logic to tables.
Key terms
Theory reminder
When a router receives a packet, it compares the destination IP address with every route in the table and decides in the following order:
Longest prefix
Among the routes that contain the destination IP, the one with the longest prefix is chosen. /32 > /24 > /16 > /0.
Administrative distance
If the same prefix comes from several sources (for example, static and OSPF), the one with the smaller AD goes into the table.
Metric
If one protocol finds several paths to a prefix, the one with the smaller metric is chosen; if equal — load sharing (ECMP).
| Code | Source | AD | Note |
|---|---|---|---|
C | Connected — a directly connected network | 0 | Appears when an interface is given an IP and is “up” |
L | Local — the interface’s own address (/32) | 0 | For packets addressed to the router itself |
S | Static — a static route | 1 | With the ip route … command |
S* | Static default route | 1 | * — a default route candidate |
D | EIGRP | 90 | Cisco protocol |
O | OSPF | 110 | Metric — cost |
R | RIP | 120 | Metric — hop count (max 15) |
B | BGP | 20 (eBGP) / 200 (iBGP) | Between providers |
Routing Table Analysis
We will work through three sample tasks step by step: reading a Cisco table, reading a Windows table and making a decision with LPM. Keep pressing the “Done” buttons.
Sample task 1. Reading Cisco show ip route
Situation: router R1 in the university’s main building. The faculty networks are connected through OSPF, the Internet through a static default route.
Codes: L - local, C - connected, S - static, R - RIP, O - OSPF, B - BGP
D - EIGRP, * - candidate default
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
10.0.0.0/8 is variably subnetted, 6 subnets, 4 masks
C 10.0.0.0/30 is directly connected, GigabitEthernet0/1
L 10.0.0.1/32 is directly connected, GigabitEthernet0/1
O 10.1.0.0/16 [110/20] via 10.0.0.2, 00:12:44, GigabitEthernet0/1
O 10.1.5.0/24 [110/30] via 10.0.0.2, 00:12:44, GigabitEthernet0/1
S 10.2.0.0/16 [1/0] via 10.0.0.2
R 10.3.0.0/16 [120/2] via 10.0.0.2, 00:00:17, GigabitEthernet0/1
192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
L 192.168.1.1/32 is directly connected, GigabitEthernet0/0
203.0.113.0/24 is variably subnetted, 2 subnets, 2 masks
C 203.0.113.0/30 is directly connected, Serial0/0/0
L 203.0.113.2/32 is directly connected, Serial0/0/0- Look at the “Gateway of last resort” line
There is a default route: unknown destinations are sent to 203.0.113.1 (the provider). With “is not set”, packets to unknown destinations would be dropped.
- Read the [AD/metric] in brackets
[110/20]— AD 110 (OSPF), cost 20.[120/2]— RIP, 2 hops.[1/0]— static. - via and the interface
via 10.0.0.2— the next-hop;GigabitEthernet0/1at the end — the outgoing interface;00:12:44— how long the route has been in the table. - Header lines
10.0.0.0/8 is variably subnetted, 6 subnets, 4 masks— this is not a route, only a grouping header: inside this large network there are 6 smaller networks with different masks. - Overlapping prefixes
10.1.0.0/16 and 10.1.5.0/24 are both in the table. For 10.1.5.77 the /24 applies, and for 10.1.9.9 the /16.
Sample task 2. Windows route print
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.105 35
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
192.168.1.0 255.255.255.0 On-link 192.168.1.105 291
192.168.1.105 255.255.255.255 On-link 192.168.1.105 291
192.168.1.255 255.255.255.255 On-link 192.168.1.105 291
10.8.0.0 255.255.0.0 10.8.0.1 10.8.0.6 25
224.0.0.0 240.0.0.0 On-link 192.168.1.105 291
255.255.255.255 255.255.255.255 On-link 192.168.1.105 291
===========================================================================
Persistent Routes:
None- Columns
Network Destination + Netmask — the prefix (the mask in dotted decimal: 255.255.255.0 = /24). Gateway — the next-hop. Interface — which local address the packet leaves from. Metric — the smaller is preferred.
- On-link
“On-link” in place of Gateway — the destination is on this segment and is sent directly (ARP asks for the destination’s own MAC address — lecture 13).
- VPN route
10.8.0.0/16 via 10.8.0.1— added when the VPN connected. That is why traffic to 10.8.x.x goes through the VPN tunnel and everything else through the home router (split tunneling). - The same on Linux
ip route:default via 192.168.1.1 dev wlan0,192.168.1.0/24 dev wlan0 proto kernel scope link src 192.168.1.105. To see the choice for a specific address:ip route get 8.8.8.8.
Lab: the longest prefix “hunter”
Below are the routes of the R1 table. Enter a destination IP or pick a ready example: the simulator checks every route, shows the matching ones in yellow and the winner in green, and explains the reason for the choice.
:ik-xarita: LPM simulator — the R1 table
| Code | Prefix | [AD/metric] | Next-hop / interface |
|---|
Sample task 3. LPM with Python
The ipaddress module reduces comparing prefixes and addresses to one line: ip in network. We find the longest prefix with max(…, key=lambda n: n.prefixlen). Follow the code step by step:
Test runs: first predict, then check
Independent tasks
7 tasks, from easy to hard. Write input() without a prompt. In each one, the :ik-tekshir: Check button tests with several test cases.
Common mistakes
| Error | Consequence | Correct answer |
|---|---|---|
| Comparing AD before prefix length | The wrong next-hop is chosen | The order: prefix → AD → metric |
| Comparing OSPF cost and RIP hop count with each other | A meaningless conclusion | Different protocols — by AD only |
| Treating the “is variably subnetted” line as a route | A route that is not in the table gets “found” | It is only a group header |
| A static route whose next-hop is a router that is not a neighbor | The recursive lookup fails — the route does not enter the table | Make the next-hop be on a directly connected network |
| Two routers point to each other as the default route | A routing loop: TTL runs out, “TTL expired in transit” | Draw the topology and check every direction; find the loop with tracert |
| Adding a route in only one direction | The request goes out, the reply does not return | The route must exist in both directions |
Boss level
Boss level: a show ip route “translator”
The first line has the number of table lines n, then n lines of show ip route (header lines — “is variably subnetted” or “Gateway of last resort” — may also appear; ignore them). Then the number of queries k and k destination IPs. For each IP find the route with the longest prefix and print:
- a route with “via”:
IP → next-hop (kod prefiks), for example10.1.5.77 → 10.0.0.2 (O 10.1.5.0/24); - “directly connected”:
IP → bevosita, interfeys (kod prefiks); - no matching route:
IP → tashlanadi.
+60 XP
Reinforcement
Review questions
What information is stored in a routing table?
The destination prefix, the route source (code), AD and metric, the next-hop or outgoing interface, the route age.
Explain the longest prefix match rule with an example.
If a /16 and a /24 both match 10.1.5.77, the /24 is chosen because it is more specific; for 10.1.9.9 only the /16 matches.
What is the difference between administrative distance and metric?
AD — trust between different sources (protocols); the metric — comparing paths within one protocol.
When do routes with codes C and L appear?
When an interface is given an IP and becomes active: C — the interface’s network, L — the interface’s own /32 address.
What is a default route and when is it used?
0.0.0.0/0 — when no other route matches; usually toward the provider.
Explain the columns of route print.
Network Destination and Netmask — the prefix; Gateway — the next-hop or On-link; Interface — the outgoing local address; Metric — preference (smaller is better).
What is a floating static route?
A static route given a larger AD than a dynamic protocol’s; it enters the table only when the main route is lost (a backup).
How do you detect a routing loop in table analysis?
Each of two routers lists the other as the next-hop for a network; in tracert the same addresses repeat and “TTL expired in transit” appears.
Independent work
The independent-study topic in the course syllabus: “Routing fundamentals and static and dynamic routing methods.” (6 hours). For your variant’s topology, build each router’s routing table by hand (in show ip route format), justify the choice for 5 destination IPs and check the result in Packet Tracer.
| Criterion | Points |
|---|---|
| Each router’s table is complete and correct (codes, AD/metric, next-hop) | 2 |
| The choice for 5 IPs is justified in the order LPM → AD → metric | 1 |
| Confirmed with Packet Tracer or terminal results | 1 |
| Topology diagram, orderly formatting | 1 |
Summary
Your lesson results
Your results are saved in this browser. Read all the sections and complete the exercises and assignments.