Skip to content

Routing_fundamentals


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 network
3. Sends to default gateway (192.168.1.1)
4. Router receives packet, looks up routing table
5. Forwards to Network B via eth1
+------------------------------------------------------------------+

Routing Table
+------------------------------------------------------------------+
Linux Routing Table:
+------------------------------------------------------------------+
$ ip route show
default via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
10.0.0.0/24 via 192.168.1.2 dev eth0
172.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 |
+------------------------------------------------------------------+
+------------------------------------------------------------------+

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 |
+---------+ +--------+
+------------------------------------------------------------------+

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 |
+------------------------------------------------------------------+
+------------------------------------------------------------------+

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 |
+------------------------------------------------------------------+
+------------------------------------------------------------------+

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 match
3. 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!
+------------------------------------------------------------------+

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 |
+------------------------------------------------------------------+
+------------------------------------------------------------------+

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
# Windows
route add 0.0.0.0 mask 0.0.0.0 192.168.1.1
# Cisco
ip 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 |
+------------------------------------------------------------------+
+------------------------------------------------------------------+

Terminal window
# View IPv4 routes
ip route show
# or
route -n
# View IPv6 routes
ip -6 route show
# Detailed route info
ip 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 details
ip route show table all
# View routing cache
ip route show cached
# Trace path to destination
traceroute 8.8.8.8
# Alternative
tracepath 8.8.8.8

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

Chapter 14: Routing Protocols


Last Updated: February 2026