What is Routing?#

Routing is the process of selecting a path for network traffic across one or more networks. Routers examine the destination IP address of each packet and decide where to forward it next.

flowchart LR
    A["Source<br/>192.168.1.10"] --> R1["Router 1"]
    R1 --> R2["Router 2"]
    R2 --> R3["Router 3"]
    R3 --> B["Destination<br/>203.0.113.50"]

Each router makes an independent forwarding decision based on its routing table — it doesn’t know the full path, only the next hop.


Routing Tables#

Every router (and every host) has a routing table:

Destination        Gateway          Interface    Metric
0.0.0.0/0          192.168.1.1      eth0         100     ← default route
192.168.1.0/24     directly connected  eth0      0       ← local network
10.0.0.0/16        10.0.0.1         eth1         50      ← static route
172.16.5.0/24      10.0.0.5         eth1         60      ← learned route

Key Fields#

FieldPurpose
DestinationNetwork prefix to match against
GatewayNext-hop IP (or “directly connected”)
InterfaceWhich NIC to send the packet out
MetricCost/preference (lower = preferred)

Longest Prefix Match#

When multiple routes match, the most specific (longest prefix) wins:

Packet destination: 10.0.5.100

Matching routes:
  0.0.0.0/0    → matches (default)
  10.0.0.0/16  → matches (more specific)
  10.0.5.0/24  → matches (MOST specific — wins!)

Default Route#

The “catch-all” route — used when no more specific route matches:

0.0.0.0/0 via 192.168.1.1

This means: “For any destination I don’t have a specific route for, send to 192.168.1.1 (my gateway).”

In cloud VPCs, the default route typically points to an Internet Gateway (for public subnets) or NAT Gateway (for private subnets).


Static vs Dynamic Routing#

AspectStaticDynamic
ConfigurationManualAutomatic (protocol)
Adapts to failuresNo (manual update)Yes (reconverges)
ScalabilitySmall networksLarge networks
CPU/memoryMinimalHigher
Use caseDefault routes, simple topologiesEnterprise, ISP, cloud

Static Route Example#

# Linux
ip route add 10.0.5.0/24 via 10.0.0.5

# AWS VPC route table
Destination: 10.0.5.0/24 → Target: VPC Peering Connection

Dynamic Routing Protocols#

Interior Gateway Protocols (IGP) — Within an Organization#

ProtocolTypeConvergenceUse Case
OSPFLink-stateFast (seconds)Enterprise, data centers
IS-ISLink-stateFastISPs, large networks
EIGRPHybridFastCisco-only environments
RIPDistance-vectorSlow (minutes)Legacy, small networks

Exterior Gateway Protocol (EGP) — Between Organizations#

BGP (Border Gateway Protocol) — the protocol that runs the internet:

flowchart LR
    AS1["AS 64500<br/>(Your Company)"] <-->|eBGP| AS2["AS 64501<br/>(ISP)"]
    AS2 <-->|eBGP| AS3["AS 64502<br/>(Cloud Provider)"]
    AS2 <-->|eBGP| AS4["AS 64503<br/>(CDN)"]
  • AS (Autonomous System): A network under single administrative control
  • eBGP: Between different ASes (internet routing)
  • iBGP: Within the same AS

BGP selects paths based on policies (not just shortest path) — this is how ISPs control traffic flow and implement peering agreements.


Routing in the Cloud (AWS)#

VPC Route Tables#

Every subnet is associated with a route table:

Public Subnet Route Table:
  10.0.0.0/16    → local (within VPC)
  0.0.0.0/0      → igw-abc123 (Internet Gateway)

Private Subnet Route Table:
  10.0.0.0/16    → local (within VPC)
  0.0.0.0/0      → nat-xyz789 (NAT Gateway)

Route Targets#

TargetPurpose
localTraffic within the VPC
igw-xxxInternet Gateway (public internet)
nat-xxxNAT Gateway (outbound internet for private subnets)
pcx-xxxVPC Peering Connection
tgw-xxxTransit Gateway
vpgw-xxxVirtual Private Gateway (VPN)
eni-xxxNetwork Interface (appliance)

Troubleshooting Routing#

# View routing table
ip route show              # Linux
route -n                   # Linux (legacy)
netstat -rn                # macOS

# Trace the path to a destination
traceroute 8.8.8.8        # shows each hop
mtr 8.8.8.8               # continuous traceroute

# Test if a route exists
ip route get 10.0.5.100   # which route would be used?

Common Issues#

SymptomLikely Cause
“No route to host”Missing route in table
Asymmetric routingDifferent paths for request/response
Black holeRoute exists but target is down
Timeout to specific subnetMissing route or security group

Key Takeaways#

  1. Longest prefix match determines which route is used
  2. Default route (0.0.0.0/0) is the catch-all — every host needs one
  3. Static routes for simple/cloud setups, dynamic for large networks
  4. BGP runs the internet — routes between autonomous systems
  5. VPC route tables control traffic flow in cloud networking
  6. traceroute shows the path packets take — essential for debugging