12 Routing Labs: Fundamentals
12.1 Learning Objectives
By the end of this chapter, you will be able to:
- Examine routing tables using system commands on Windows, Linux, and macOS platforms
- Interpret route entries distinguishing connected routes, static routes, and default gateways
- Trace network paths using traceroute to map routing hops and diagnose latency
- Configure ESP32 networking to retrieve gateway information and verify routing decisions
- Refute routing misconceptions such as “more routes = better connectivity” with evidence
For Beginners: Routing Labs
These hands-on labs let you practice routing concepts by configuring devices and watching how data travels through a network. No prior experience needed – each exercise starts simple and builds up, like learning to navigate a small town before tackling a big city highway system.
Sensor Squad: Hands on the Keyboard!
“Time to look at a real routing table,” said Max the Microcontroller. “On your computer, you can type route print on Windows, netstat -rn on Linux, or netstat -nr on macOS to see how your own device routes packets.”
“You will see entries for connected networks, static routes, and the default gateway,” explained Sammy the Sensor. “The default gateway is especially important – it is the address your computer sends packets to when it does not know where a destination is.”
“Traceroute is another amazing tool,” added Lila the LED. “It shows every router between you and a destination by sending packets with increasing TTL values. Each router that drops a packet sends back an error message, revealing its address. You can literally map the internet path!”
“We even get to program an ESP32 to read its gateway information,” said Bella the Battery. “IoT devices need to know their default gateway to send data to the cloud. This lab shows you exactly how that works in embedded code.”
Related Chapters
Lab Series:
- Routing Labs: Overview - Lab series introduction and quiz
- Routing Labs: Advanced - ESP32 packet forwarding and convergence simulation
- Routing Labs: Algorithms - Python implementations of routing algorithms
Core Concepts:
- Routing Fundamentals - Core routing theory and concepts
- Routing Comprehensive Review - Advanced routing strategies
IoT Routing:
- RPL Fundamentals - Low-power routing protocol
- RPL Labs - Hands-on RPL implementation
Learning:
- Simulations Hub - Routing simulators and tools
- Videos Hub - Routing video tutorials
12.2 Prerequisites
These labs build on the core routing theory. You will find them easier if you have already studied:
- Networking Basics - IP addressing, subnets, and default gateways
- Layered Models: Fundamentals - How the network layer fits into the stack
- Routing Fundamentals - Static vs dynamic routing, metrics, and longest-prefix match
You should also be comfortable running simple commands in a terminal (PowerShell, Command Prompt, or a Linux shell).
Key Concepts
- Cisco Packet Tracer: A free network simulation tool widely used for learning routing concepts; supports configuring routers, switches, and hosts with Cisco IOS commands.
- Static Route Configuration: The manual process of adding
ip route <destination> <mask> <next-hop>entries to a router’s configuration. - Ping (ICMP Echo): A network diagnostic sending ICMP Echo Request packets to test reachability; the response confirms the path to the destination is working.
- Traceroute: A diagnostic tool that maps the route a packet takes by sending packets with incrementing TTL values and collecting ICMP Time Exceeded responses.
- Subnet: A logical subdivision of an IP network identified by a network prefix (e.g., 192.168.1.0/24); routers connect separate subnets.
12.3 Lab 1: View Routing Table
Objective: Examine the routing table on your system.
12.3.1 Windows:
route print
# OR
netstat -r12.3.2 macOS/Linux:
route -n
# OR
ip route show
# OR
netstat -rnExpected output:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 wlan0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 wlan0
Interpretation:
- 0.0.0.0 = Default route (all unknown destinations)
- 192.168.1.0 = Connected local network
- 192.168.1.1 = Default gateway
Understanding the Output
| Field | Meaning |
|---|---|
| Destination | Target network or host |
| Gateway | Next hop router (0.0.0.0 means direct delivery) |
| Genmask | Subnet mask defining network size |
| Flags | U=Up, G=Gateway, H=Host route |
| Metric | Route cost (lower = preferred) |
| Iface | Network interface to use |
12.3.3 Route Types Explained
12.4 Common Misconception: More Routes = Better
Common Misconception: “More Routes = Better Connectivity”
The Misconception: Many beginners believe that adding more routes to the routing table improves network connectivity and performance. They think: “If I add 10 static routes, my network will be 10x faster!”
The Reality: Routing tables don’t generate connectivity - they document existing paths. Adding routes without corresponding network interfaces or gateways does nothing. Worse, incorrect routes break working connections.
Real-World Impact (Quantified):
Case 1: Route Overload on IoT Gateway
- System: 50-sensor LoRaWAN gateway with 2 interfaces (Wi-Fi + Ethernet)
- Misconfiguration: Admin added 247 static routes “just in case” for future subnets
- Result:
- Route lookup time: 2ms to 45ms (22.5x slower)
- Packet forwarding rate: 1,000 pps to 180 pps (82% drop)
- CPU utilization: 12% to 67% (routing table scans)
- Gateway became bottleneck for entire sensor network
Case 2: Duplicate Routes Causing Flapping
- System: Industrial PLC with dual Ethernet (production + backup)
- Misconfiguration: Two default routes with equal metrics to different gateways
- Result:
- Connections to cloud server flapped every 30 seconds (load balancing)
- TCP sessions reset repeatedly (different source IPs per gateway)
- Data loss: 18% of MQTT messages failed (session disruption)
- Downtime: 4 hours until correct metric prioritization configured
Case 3: Missing Connected Route
- System: ESP32 with static IP 192.168.1.100/24, gateway 192.168.1.1
- Misconfiguration: Manually added routes, forgot connected route for 192.168.1.0/24
- Result:
- Device could NOT communicate with local devices (192.168.1.50, etc.)
- All local traffic incorrectly forwarded to gateway (192.168.1.1)
- Gateway rejected and looped packets back (routing loop!)
- Network admin manually pinged device: “Why isn’t it responding?!”
12.4.1 Key Routing Principles
| Principle | Explanation | Example |
|---|---|---|
| Routes document paths, don’t create them | A route to 10.0.0.0/8 is useless if no interface can reach that network | Adding ip route 10.0.0.0 255.0.0.0 192.168.1.254 won’t work if 192.168.1.254 doesn’t exist |
| Fewer, specific routes > Many generic routes | 3 well-designed routes outperform 50 redundant routes | Home network: 192.168.1.0/24 connected, 10.0.0.0/8 via VPN, 0.0.0.0/0 via ISP |
| Default route is your safety net | If you have a default route (0.0.0.0/0), you rarely need additional static routes | Most IoT devices need ONLY: connected routes (automatic) + default gateway (1 route) |
| Equal-metric routes = Load balancing OR flapping | Two routes to same destination with equal cost causes round-robin | Avoid equal metrics for failover - use different metrics (10 vs 100) |
12.4.2 Correct Approach for IoT Devices
Minimal routing table (ESP32, Arduino, Raspberry Pi):
Destination Gateway Interface Type
192.168.1.0/24 0.0.0.0 wlan0 Connected (automatic)
0.0.0.0/0 192.168.1.1 wlan0 Default (one static route)
That’s it! Two routes. One connected (automatic), one default (configured). Covers 100% of destinations.
12.5 Lab 2: Traceroute
Objective: Map the path packets take to a destination.
# Windows
tracert google.com
# macOS/Linux
traceroute google.comSample output:
1 192.168.1.1 (Gateway) 1.234 ms
2 10.0.0.1 (ISP Router) 5.678 ms
3 203.0.113.1 (Regional) 12.345 ms
4 198.51.100.1 (Backbone) 18.901 ms
...
15 142.250.185.46 (google.com) 25.678 ms
Each line = One router (hop) along the path
12.5.1 Understanding Traceroute Output
12.5.2 Common Traceroute Patterns
| Pattern | Meaning | Example |
|---|---|---|
* * * |
Router not responding to ICMP | Firewall blocking, stealth router |
| Increasing latency | Normal - each hop adds delay | 1ms, 5ms, 12ms, 25ms |
| Sudden jump | Geographic distance or congestion | 12ms to 180ms (crossing ocean) |
| Same IP repeated | Routing loop or load balancer | Same IP at hops 5, 6, 7 |
| Private IPs (10.x, 192.168.x) | Internal network hops | Your ISP’s internal routing |
Traceroute for IoT Debugging
Use traceroute to diagnose:
- Cloud connection issues: See where packets get stuck
- High latency: Identify congested hops
- Routing loops: Detect loops before TTL expires
- Path changes: Compare traces over time
12.6 Lab 3: Configure Static Route (ESP32 Example)
Objective: Add a static route on IoT device.
#include <WiFi.h>
const char* ssid = "YourNetwork";
const char* password = "YourPassword";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\n\n=== Default Gateway ===");
Serial.print("Gateway: ");
Serial.println(WiFi.gatewayIP());
// In production, you might need to add static routes
// for VPN or multi-homed networks
// (ESP32 doesn't directly support static routes via API,
// but gateway configuration determines default path)
}
void loop() {
// Your application
}
Try It: ESP32 Network Information Simulator
Run this code to see how ESP32 retrieves gateway and network configuration. The simulator shows the connection process and displays the default gateway IP.
What to Observe:
- Gateway IP: The router address that forwards packets to other networks
- Routing Decisions: ESP32 sends all internet-bound traffic to this gateway
- Try: Modify code to print
WiFi.localIP()andWiFi.subnetMask()for full routing context
Note: Most IoT devices use single default route to gateway. Multi-route scenarios typically handled by gateway/router.
12.6.1 ESP32 Network Stack
12.7 Lab Network Topology Overview
Before diving into advanced labs, let’s visualize a typical multi-router lab network topology that demonstrates routing concepts:
Lab Scenarios You Can Test
This topology enables hands-on practice with:
- Direct Delivery (PC1 to ESP1): Both on 192.168.1.0/24, packets delivered locally without routing
- Single Hop Routing (PC1 to IoT1): R1 forwards to R2 (one hop between networks)
- Multi-Hop Routing (PC1 to Server): Packets traverse R1 to R2 to R3 or R1 to R3 (metric decides)
- Default Route Testing (PC1 to Internet): All unknown destinations forward via R1 to ISP
- Path Selection (R1 to R3): Direct link (metric 5) vs via R2 (metric 11), demonstrates lowest-cost path selection
- TTL Tracking: traceroute from PC1 to DB shows TTL decrement at each hop
Putting Numbers to It
How fast is route lookup in practice? Consider a router forwarding 1 Gbps traffic (100-byte packets = 1.25 million packets/second).
Linear search (check each route sequentially): - 100,000 routes in table - Average 50,000 comparisons per lookup - At 2 ns per comparison: \(50{,}000 \times 2\text{ ns} = 100\text{ µs per packet}\) - Maximum throughput: \(1 / 100\text{ µs} = 10{,}000\text{ packets/sec}\) = 8 Mbps (bottleneck!)
Longest prefix match (binary trie data structure): - Lookup time: \(O(\log_2 n) = \log_2(100{,}000) \approx 17\) comparisons - At 2 ns per comparison: \(17 \times 2 = 34\text{ ns per packet}\) - Maximum throughput: \(1 / 34\text{ ns} \approx 29.4\text{ million packets/sec}\) = 23.5 Gbps (no bottleneck)
Hardware CAM (Content Addressable Memory - modern routers): - Parallel lookup: all routes checked simultaneously in 1 clock cycle (< 5 ns) - Maximum throughput: \(1 / 5\text{ ns} = 200\text{ million packets/sec}\) = 160 Gbps
Real-world impact: A $50 home router uses software lookup (34 ns) → handles 1 Gbps fine. A $10,000 enterprise router uses CAM → handles 100 Gbps. Algorithm choice determines hardware cost!
Common Pitfalls
1. Not Verifying Routing Tables After Configuration
Adding a static route command doesn’t guarantee the route is installed correctly. Always view the routing table after configuration to confirm the route appears with the correct prefix, mask, and next-hop.
2. Using Ping to Troubleshoot Without Checking Both Directions
A ping failure might mean the request doesn’t reach the destination OR the reply doesn’t reach the source. Check routing tables at both ends and trace both directions of the path independently.
3. Confusing the Lab Network Addressing With Real-World Addressing
Lab exercises use private IP ranges (10.x.x.x, 192.168.x.x) that differ from production addressing. When transitioning from lab to production, verify all address ranges, subnet masks, and default gateways are updated.
12.8 Summary
- Viewing routing tables with
route print(Windows) orip route show(Linux/macOS) reveals how your system makes forwarding decisions - Routing table entries include connected routes (automatic), static routes (manual), and default routes (catch-all)
- Traceroute maps the complete path packets take by incrementing TTL values and capturing ICMP responses
- ESP32 gateway configuration determines where non-local packets are forwarded since most IoT devices use a single default route
- Common misconceptions about routing tables include thinking more routes improve performance when in reality minimal, correct routes are optimal
- Route types (connected, static, default) serve different purposes and are selected based on longest-prefix matching
12.9 Knowledge Check
Common Mistake: Configuring Static Routes Without Testing Reachability
The Mistake: Administrators add static routes to routing tables without verifying that the next-hop gateway is actually reachable. The route appears in the routing table, but packets get dropped because the next hop doesn’t respond.
Real-World Example:
Scenario: IoT gateway for 50 environmental sensors needs to reach corporate data center at 172.16.0.0/16
Administrator configures:
# Add static route to data center
ip route add 172.16.0.0/16 via 192.168.1.254
# Check routing table
ip route show
# Output: 172.16.0.0/16 via 192.168.1.254 dev eth0Result: Routing table shows the route, but sensors can’t reach data center!
What Went Wrong:
Problem 1: Next-Hop Not in Local Subnet
# Gateway IP configuration
ip addr show eth0
# Output: inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
# Next-hop specified: 192.168.1.254
# Local subnet: 192.168.1.0/24 (covers .1 to .254)
# Next-hop IS in local subnet ✓
# BUT: Is 192.168.1.254 actually online?
ping 192.168.1.254 -c 4
# Output: 100% packet loss (0 received)Why This Happens: The next-hop router 192.168.1.254 doesn’t exist or is offline. The static route references a non-existent gateway.
Problem 2: ARP Cannot Resolve Next-Hop MAC Address
# Check ARP table
arp -n | grep 192.168.1.254
# Output: (empty - no ARP entry)
# The gateway tries to forward packets to 192.168.1.254
# But without MAC address, packets cannot be sent at Layer 2
# Packets are queued then droppedCorrect Configuration Process:
Step 1: Verify Next-Hop Reachability
# Ping the next-hop gateway FIRST
ping 192.168.1.254 -c 4
# Expected output:
# 64 bytes from 192.168.1.254: icmp_seq=1 ttl=64 time=1.2 ms
# 4 packets transmitted, 4 received, 0% packet loss
# If ping fails, next hop is unreachable - DO NOT add static routeStep 2: Check ARP Resolution
# After successful ping, check ARP table
arp -n | grep 192.168.1.254
# Expected output:
# 192.168.1.254 ether aa:bb:cc:dd:ee:ff C eth0
# This confirms Layer 2 reachabilityStep 3: Add Static Route
# NOW add the static route
ip route add 172.16.0.0/16 via 192.168.1.254
# Verify installation
ip route show | grep 172.16
# Output: 172.16.0.0/16 via 192.168.1.254 dev eth0Step 4: Test End-to-End Connectivity
# Test actual destination reachability
ping 172.16.0.10 -c 4
# Expected output:
# 64 bytes from 172.16.0.10: icmp_seq=1 ttl=62 time=15 ms
# 4 packets transmitted, 4 received, 0% packet loss
# If this fails, problem is beyond the next hop (e.g., return routing)Diagnostic Checklist:
| Test | Command | Pass Criteria | If Fails |
|---|---|---|---|
| Next-hop ping | ping 192.168.1.254 |
0% packet loss | Next hop unreachable - check cabling/config |
| ARP resolution | arp -n \| grep 192.168.1.254 |
MAC address present | Layer 2 issue - check switch/VLAN |
| Route installed | ip route show \| grep 172.16 |
Route visible in table | Syntax error or permission issue |
| Destination ping | ping 172.16.0.10 |
0% packet loss | Return path issue or firewall blocking |
| Traceroute | traceroute 172.16.0.10 |
Shows path via 192.168.1.254 | Routing loop or asymmetric path |
IoT Gateway Automation (Prevent This Mistake):
#!/bin/bash
# safe-static-route.sh - Add static route only if next-hop reachable
DESTINATION="172.16.0.0/16"
NEXTHOP="192.168.1.254"
INTERFACE="eth0"
echo "Testing reachability of next-hop $NEXTHOP..."
if ping -c 3 -W 2 "$NEXTHOP" > /dev/null 2>&1; then
echo "Next-hop reachable. Adding static route..."
ip route add "$DESTINATION" via "$NEXTHOP" dev "$INTERFACE"
# Verify route installation
if ip route show | grep -q "$DESTINATION"; then
echo "Route added successfully:"
ip route show | grep "$DESTINATION"
else
echo "ERROR: Route installation failed"
exit 1
fi
else
echo "ERROR: Next-hop $NEXTHOP is unreachable. Route NOT added."
exit 1
fiKey Takeaways:
- Always ping next-hop before adding static route – verify reachability
- Check ARP resolution to confirm Layer 2 connectivity
- Test end-to-end after adding route to verify full path
- Automate validation in deployment scripts to prevent human error
- Monitor next-hop availability – if gateway goes down, route becomes useless even if still in table
Why This Matters for IoT: IoT gateways often operate remotely with limited physical access. A misconfigured static route can cause hours of downtime while technicians travel to site, when the issue could have been prevented with 30 seconds of ping testing before deployment.
Concept Relationships
This lab builds upon:
- Networking Basics - IP addressing, subnets, default gateways
- Layered Models: Fundamentals - Network layer operation
- Routing Fundamentals - Core routing theory
This lab connects to:
- Routing Labs: Advanced - Packet forwarding and convergence
- Routing Labs: Algorithms - Algorithmic foundations
- TTL and Loop Prevention - How traceroute exploits TTL
Real-world applications:
- IoT gateway configuration for cloud connectivity
- Troubleshooting sensor-to-cloud paths with traceroute
- Designing redundant uplinks for critical deployments
See Also
Command Reference:
- Windows Routing: Microsoft Docs - route command
- Linux Routing: ip route manual
- Traceroute Tutorial: Cloudflare - What is traceroute?
ESP32 Networking:
Related Labs:
- Network Topologies Labs - Topology design exercises
- RPL Labs - IoT-specific routing practice
12.10 What’s Next
| Previous | Up | Next |
|---|---|---|
| Routing Labs and Quiz | Routing Labs and Quiz | Routing Labs: Advanced |
Continue to Routing Labs: Advanced for hands-on ESP32 packet forwarding simulation and Python convergence visualization.
Alternatively, explore Routing Labs: Algorithms for Python implementations of routing table lookup, Dijkstra’s algorithm, and distance vector protocols.