Routing determines how packets travel from source to destination across networks. Routers examine destination IP addresses and forward packets based on routing tables.
Key Concepts
- Routing table - List of destinations and next hops
- Default gateway - Where to send packets when no specific route matches
- Metric/Cost - Route preference (lower = preferred)
- Hop - Each router a packet passes through
Viewing the Routing Table
- Linux:
ip route showorroute -n - macOS:
netstat -rn - Windows:
route print
Static vs Dynamic Routing
| Type | Description | Use Case |
|---|---|---|
| Static | Manually configured routes | Small networks, specific paths |
| Dynamic | Routes learned via protocols | Large networks, redundancy |
Dynamic Routing Protocols
Interior Gateway Protocols (IGP)
Used within an autonomous system (AS).
| Protocol | Type | Use Case |
|---|---|---|
| OSPF | Link-state | Large enterprise networks |
| IS-IS | Link-state | ISPs, large networks |
| RIP | Distance-vector | Small networks (legacy) |
| EIGRP | Hybrid | Cisco environments |
Exterior Gateway Protocols (EGP)
| Protocol | Use Case |
|---|---|
| BGP | Internet routing, between ISPs and large networks |
BGP (Border Gateway Protocol)
The protocol that makes the internet work. BGP routers exchange reachability information between autonomous systems.
Key Concepts
- AS (Autonomous System) - Network under single administrative control
- ASN - Unique AS number (e.g., AS15169 for Google)
- Peering - BGP connections between ASes
- Prefix announcement - Advertising IP ranges you own
Why BGP Matters
- Multihoming - Connect to multiple ISPs for redundancy
- Traffic engineering - Control inbound/outbound traffic paths
- DDoS mitigation - Null-route or redirect attack traffic
BGP Looking Glass
View BGP routing tables from ISP perspectives:
Policy-Based Routing
Route based on criteria beyond destination (source IP, port, protocol). Useful for sending specific traffic through different paths.
Linux as a Router
Linux can function as a router by enabling IP forwarding and configuring NAT (masquerade) for outbound traffic.
Common Issues
| Issue | Cause | Solution |
|---|---|---|
| No route to host | Missing route | Add route or check gateway |
| Asymmetric routing | Different path in/out | Check routing tables both directions |
| Black hole | Route to null | Remove route or fix next hop |
| Route flapping | Unstable link | Check physical connection, dampening |
See Network Troubleshooting for diagnostic tools.