Routing_fundamentals
Chapter 13: Routing Fundamentals
Section titled “Chapter 13: Routing Fundamentals”13.1 What is Routing?
Section titled “13.1 What is Routing?”Routing is the process of forwarding packets from one network to another.
Routing Overview+------------------------------------------------------------------+
Network A (192.168.1.0/24) Network B (10.0.0.0/24)+--------------------+ +--------------------+| Host A1 | | Host B1 || 192.168.1.10 | | 10.0.0.10 |+--------+ | | +--------+ | | | | +----+ | +-------+ +----+ | | | | | +----+----+ | | +------+------+ | Switch | | | | Switch | +----+----+ | | +------+------+ | | | | +------+ +------+------+ | +-----+-----+ | Router | | eth0: eth1| |10.0.0.1 192.168.1.1 +-----+-----+ | | | +-----+-----+ | Network A | | Gateway | +-----------+
Process:1. Host A1 wants to send to Host B1 (10.0.0.10)2. Checks destination: different network3. Sends to default gateway (192.168.1.1)4. Router receives packet, looks up routing table5. Forwards to Network B via eth1
+------------------------------------------------------------------+13.2 Routing Table
Section titled “13.2 Routing Table” Routing Table+------------------------------------------------------------------+
Linux Routing Table:+------------------------------------------------------------------+$ ip route showdefault via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.100192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10010.0.0.0/24 via 192.168.1.2 dev eth0172.16.0.0/16 dev tun0 scope link+------------------------------------------------------------------+
Fields:+------------------------------------------------------------------+| - Destination: Network or host address || - Gateway: Next hop router || - Genmask: Subnet mask for destination || - Flags: Route properties (U=up, H=host, G=gateway) || - Metric: Cost (lower = preferred) || - Interface: Outgoing interface |+------------------------------------------------------------------+
Routing Table Types:+------------------------------------------------------------------+| Type | Description ||----------------|--------------------------------------------------|| Direct | Same network, no router needed || Indirect | Different network, requires router || Default | Catch-all for unknown destinations || Static | Manually configured || Dynamic | Learned via routing protocols |+------------------------------------------------------------------+
+------------------------------------------------------------------+13.3 Routing Decision Process
Section titled “13.3 Routing Decision Process” Packet Routing Decision+------------------------------------------------------------------+
Incoming Packet | v +------------------------+ | Extract Destination IP| +------------------------+ | v +------------------------+ | Is Destination in | | Local Subnet? | +------------------------+ | Yes / \ No / \ v v +---------+ +------------------------+ |ARP for | | Check Routing Table | |Target | +------------------------+ +---------+ | v +------------------------+ | Match Found? | +------------------------+ | \ Yes / \ No / \ v v +---------+ +------------------------+ |Forward | | Check Default Route | |to Local | +------------------------+ |or Drop | | Yes/ \No / \ v v +---------+ +--------+ |Forward | |Drop | |via GW | |Packet | +---------+ +--------+
+------------------------------------------------------------------+13.4 Types of Routing
Section titled “13.4 Types of Routing”Static Routing
Section titled “Static Routing”Manually configured routes.
Static Routing Example+------------------------------------------------------------------+
Network Topology:+------------------------------------------------------------------+
Network A Network B Network C 192.168.1.0/24 10.0.0.0/24 172.16.0.0/24 <---------> <---------> <--------->
+--------+ +--------+ +--------+ | Host A | | Router1| | Host C | +--------+ +--------+ +--------+ | | | | | eth1 (10.0.0.1) | | eth0 | | +-----+-----+ | +-----+-----+ | Router0 | | | Router2 | +-----------+ | +-----------+ eth0:192.168.1.1 eth0
Static Routes on Router0:+------------------------------------------------------------------+| # To reach Network B || ip route add 10.0.0.0/24 via 192.168.1.2 dev eth0 || || # To reach Network C || ip route add 172.16.0.0/24 via 192.168.1.2 dev eth0 |+------------------------------------------------------------------+
Static Route Advantages:+------------------------------------------------------------------+| - Predictable, no routing overhead || - Low CPU/memory usage || - Secure (no external routing updates) |+------------------------------------------------------------------+
Static Route Disadvantages:+------------------------------------------------------------------+| - Doesn't scale || - No failover || - Manual updates required |+------------------------------------------------------------------+
+------------------------------------------------------------------+Dynamic Routing
Section titled “Dynamic Routing”Routes learned via routing protocols.
Dynamic Routing+------------------------------------------------------------------+
Routing Protocols:+------------------------------------------------------------------+| Category | Protocol | Type | Use Case ||--------------|------------|------------|------------------------|| IGP (Interior)| OSPF | Link-State | Enterprise LAN || | EIGRP | Hybrid | Cisco networks || | RIP | Distance | Small/simple networks || | IS-IS | Link-State | Large telco || EGP (Exterior)| BGP | Path-Vector| ISP/Internet |+------------------------------------------------------------------+
+------------------------------------------------------------------+13.5 Longest Prefix Match
Section titled “13.5 Longest Prefix Match”Router selects the most specific route (longest match).
Longest Prefix Match+------------------------------------------------------------------+
Routing Table:+------------------------------------------------------------------+| Destination | Gateway | Interface || 0.0.0.0/0 | 192.168.1.1 | eth0 | Default| 192.168.1.0/24 | directly conn | eth0 | Local| 10.0.0.0/8 | 192.168.1.2 | eth1 || 10.1.0.0/16 | 192.168.1.3 | eth1 || 10.1.5.0/24 | 192.168.1.4 | eth1 |+------------------------------------------------------------------+
Packet to 10.1.5.100:+------------------------------------------------------------------+
Check each route (longest match first):
1. 0.0.0.0/0 - Match (/0 = 0 bits) [Lowest priority]2. 192.168.1.0/24 - No match3. 10.0.0.0/8 - Match (/8 = 8 bits)4. 10.1.0.0/16 - Match (/16 = 16 bits)5. 10.1.5.0/24 - Match (/24 = 24 bits) ← HIGHEST priority
Result: Forward via 192.168.1.4
This is why /32 (host) routes are most specific!
+------------------------------------------------------------------+13.6 Routing Metrics
Section titled “13.6 Routing Metrics” Routing Metrics+------------------------------------------------------------------+
Metric: Value used to determine best path+------------------------------------------------------------------+
Common Metrics:+------------------------------------------------------------------+| Metric | Description ||----------------|--------------------------------------------------|| Hop Count | Number of routers to cross || Bandwidth | Link capacity (higher = better) || Delay | Time to reach destination (lower = better) || Cost | Administrative cost (Cisco OSPF) || Reliability | Link reliability (higher = better) || MTU | Maximum transmission unit |+------------------------------------------------------------------+
Example: OSPF Cost+------------------------------------------------------------------+| Link Speed | Cost Formula | Cost ||----------------|-------------------|---------|| 10 Mbps | 100/10 = 10 | 10 || 100 Mbps | 100/100 = 1 | 1 || 1 Gbps | 100/1000 = 0.1 → 1| 1 || 10 Gbps | 100/10000 = 0.01 →1| 1 |+------------------------------------------------------------------+
+------------------------------------------------------------------+13.7 Default Gateway
Section titled “13.7 Default Gateway” Default Gateway+------------------------------------------------------------------+
Purpose: Route for unknown destinations
When is default used?+------------------------------------------------------------------+| - Destination not in local subnet || - No specific route matches || - Catch-all route |+------------------------------------------------------------------+
Setting Default Gateway:+------------------------------------------------------------------+
# Linux (temporary)sudo ip route add default via 192.168.1.1
# Linux (permanent - /etc/sysconfig/network-scripts/route-eth0)default via 192.168.1.1 dev eth0
# Windowsroute add 0.0.0.0 mask 0.0.0.0 192.168.1.1
# Ciscoip route 0.0.0.0 0.0.0.0 192.168.1.1
+------------------------------------------------------------------+
Default Route Notation:+------------------------------------------------------------------+| 0.0.0.0/0 or ::/0 (IPv6) || Also called "quad-zero" route |+------------------------------------------------------------------+
+------------------------------------------------------------------+13.8 View Routing Table on Linux
Section titled “13.8 View Routing Table on Linux”# View IPv4 routesip route show# orroute -n
# View IPv6 routesip -6 route show
# Detailed route infoip route get 8.8.8.8
# Example output:# 8.8.8.8 via 192.168.1.1 dev eth0 src 192.168.1.100
# Show all routes with detailsip route show table all
# View routing cacheip route show cached
# Trace path to destinationtraceroute 8.8.8.8
# Alternativetracepath 8.8.8.8Summary
Section titled “Summary”In this chapter, you learned:
- ✅ What is routing and how it works
- ✅ Routing table structure and fields
- ✅ Routing decision process
- ✅ Static vs Dynamic routing
- ✅ Longest Prefix Match
- ✅ Routing metrics
- ✅ Default gateway
Next Chapter
Section titled “Next Chapter”Last Updated: February 2026