IP routing is the fundamental mechanism that moves packets across networks to reach their destination.
The Routing Problem
Question: How does a packet get from a server in New York to a server in Tokyo?
Answer: Through a series of routers, each making a forwarding decision based on routing tables.
Routing Table Basics
A routing table is a list of rules that tells the router: "If destination is X, send packet via Y."
View routing table (Linux):
route -n
# or
ip route show
# Example output:
# Kernel IP routing table
# Destination Gateway Genmask Flags Metric Iface
# 0.0.0.0 192.168.1.1 0.0.0.0 UG 100 eth0
# 192.168.1.0 0.0.0.0 255.255.255.0 U 0 eth0
# 127.0.0.0 0.0.0.0 255.255.255.0 U 256 loRouting Table Columns
| Column | Meaning | Example |
|---|---|---|
| Destination | Target network | 192.168.1.0 |
| Gateway | Next hop router | 192.168.1.1 |
| Genmask | Network mask | 255.255.255.0 |
| Flags | Route type | U (up), G (gateway) |
| Metric | Route priority | 0 = prefer this |
| Iface | Interface to use | eth0 |
Routing Decision Process
Scenario: Packet destined for 8.8.8.8 arrives at your router
Step 1: Check Destination
Is 8.8.8.8 in my routing table?
Step 2: Longest Prefix Match Find the most specific matching route:
Route 1: 8.0.0.0/8 via 192.168.1.1
Route 2: 8.8.0.0/16 via 10.0.0.1
Route 3: 8.8.8.0/24 via 10.1.0.1
Route 4: 0.0.0.0/0 via 192.168.1.1 (default)
For destination 8.8.8.8:
✓ Route 1: matches (prefix /8)
✓ Route 2: matches (prefix /16)
✓ Route 3: matches (prefix /24) ← MOST SPECIFIC
✗ Route 4: matches but less specific
Decision: Use Route 3
Step 3: Forward
Add packet to queue for next-hop router 10.1.0.1
Use interface eth1 (from routing table)
Send packet!
Step 4: Next Router If 10.1.0.1 isn't the final destination, it repeats the process with its routing table.
Routing Scopes
Local Route Directly connected network:
Destination: 192.168.1.0/24
Gateway: 0.0.0.0 (on-link)
Interface: eth0
→ Deliver directly on local network (using ARP)
Remote Route Network reachable via gateway:
Destination: 10.0.0.0/8
Gateway: 192.168.1.1 (router IP)
Interface: eth0
→ Send to gateway, gateway forwards further
Default Route Fallback for everything else:
Destination: 0.0.0.0/0 (matches any IP)
Gateway: 192.168.1.1
Interface: eth0
→ "When in doubt, send to gateway"
Common Routes
Loopback:
127.0.0.0/8 → 127.0.0.1 (lo interface)
All local services reach loopback device
Broadcast:
192.168.1.255/32 (depends on network)
Broadcast address of your network
Link-Local:
169.254.0.0/16 → auto-assigned if DHCP fails
Temporary connectivity between neighbors
Static vs Dynamic Routes
Static Routes Manually configured, doesn't change:
# Add a static route
sudo ip route add 10.0.0.0/8 via 192.168.1.1
# Make permanent (Linux)
# Add to /etc/netplan/00-installer-config.yaml or /etc/network/interfacesDynamic Routes Learned automatically via routing protocols:
- RIP (Routing Information Protocol)
- OSPF (Open Shortest Path First)
- BGP (Border Gateway Protocol)
Metric: Route Priority
When multiple routes match, metric determines priority (lower = better):
Route 1: 10.0.0.0/8 via 192.168.1.1 metric 100
Route 2: 10.0.0.0/8 via 10.1.0.1 metric 50
Decision: Use Route 2 (lower metric)
Common Metrics:
- Hop count (number of routers)
- Bandwidth
- Latency
- Reliability
- Load
Multi-Path Routing
Send traffic via multiple paths simultaneously (Equal-Cost Multi-Path - ECMP):
Destination 8.8.8.8:
Route 1: via 192.168.1.1 metric 100
Route 2: via 10.0.0.1 metric 100
Same cost → load balance between both routes
25% traffic on route 1
25% traffic on route 2
(example simplified)
Benefits:
- Higher throughput
- Redundancy — if one path fails, use other
- Better utilization
TTL (Time To Live)
Prevents infinite routing loops:
Packet TTL: 64
Router 1: TTL 64 → TTL 63 → Forward
Router 2: TTL 63 → TTL 62 → Forward
Router 3: TTL 62 → TTL 61 → Forward
...
Router N: TTL 2 → TTL 1 → Forward
Router N+1: TTL 1 → TTL 0 → DROP
ICMP "Time Exceeded" sent back to source
Traceroute Uses TTL:
traceroute google.com
# Sends packets with increasing TTL
# Each router responds with ICMP Time Exceeded
# Shows entire path to destinationRouting Problems
Problem 1: No Route Found
Destination: 10.0.0.50
Routing table has no entry for 10.0.0.0/...
No default route configured
Result: ICMP "Destination Unreachable" → packet dropped
Solution: Add route or configure default gateway
Problem 2: Asymmetric Routing
Outbound path: A → Router 1 → Router 2 → B
Return path: B → Router 3 → Router 4 → A
Speeds differ, latency differs
Firewalls may reject return traffic
Problem 3: Routing Loop
Router A: "10.0.0.0 is via Router B"
Router B: "10.0.0.0 is via Router A"
Packet bounces forever
TTL reaches 0, packet dies
(Lots of wasted bandwidth in the meantime)
Solution: Use dynamic routing protocols that detect loops
Routing in Containers/Kubernetes
Container Network:
Pod IP: 10.244.1.50
Container gets default route: 0.0.0.0/0 → bridge
Bridge gateway forwards to Kubernetes network plugin
CNI (Container Network Interface) routes between nodes
Example:
Pod A (Node 1): 10.244.1.50
Pod B (Node 2): 10.244.2.50
Pod A's routing table:
10.244.1.0/24 → local (eth0)
10.244.0.0/14 → default gateway (CNI plugin)
Pod A sends to 10.244.2.50
→ CNI plugin sees it, knows Node 2 has 10.244.2.0/24
→ Tunnels or routes packet to Node 2
→ Node 2 delivers to Pod B
Viewing Detailed Routes
Linux — Advanced Routing Table View:
# Show all routes with more details
ip route show table all
# Show routes added by specific source
ip route show from 192.168.1.100
# Show routes to specific prefix
ip route show 10.0.0.0/8
# Show route taken for specific destination (where-to)
ip route get 8.8.8.8Adding and Removing Routes
Add a static route:
# One-time (temporary)
sudo ip route add 10.0.0.0/8 via 192.168.1.1
# Permanent (different for each distribution)
# Debian/Ubuntu: /etc/network/interfaces
# RedHat/CentOS: /etc/sysconfig/network-scripts/route-*
# Netplan: /etc/netplan/*.yamlRemove a route:
sudo ip route del 10.0.0.0/8Routing Best Practices for DevOps
✓ Always configure default gateway
✓ Document static routes (crucial for debugging)
✓ Use dynamic routing for complex networks
✓ Monitor for asymmetric routes
✓ Test routes with traceroute and mtr
✓ Ensure firewall allows traffic in both directions
✓ Avoid routing loops — use proper routing protocols
✓ Set appropriate TTL for your use case
Key Concepts
- Routing table = rules for forwarding packets
- Longest prefix match = most specific route wins
- Metric = priority; lower is better
- Default route = fallback (0.0.0.0/0)
- Dynamic routes learned via routing protocols (RIP, OSPF, BGP)
- TTL prevents infinite loops
- Traceroute shows path by incrementing TTL
- Every router forwards based on its local routing table
- No routing loop detection needed (TTL handles it)