AlgoInsight

Free lesson · Computer Networking

Add a static route: traffic for 10.0.2.0/24 goes via 10.0.1.1

Easy10 min readnetworkingcomputer-networkstcp-ip

Two Ways to Build a Routing Table

In the previous topic, you learned that routers use a forwarding table to determine where to send each packet. But how does that table get populated? There are exactly two ways: a human administrator manually configures routes (static routing), or routing protocols automatically discover and compute routes (dynamic routing). Every network on the planet uses one or both of these approaches, and the choice between them shapes the network's resilience, complexity, and operational burden.

Understanding the trade-offs between static and dynamic routing is not just an academic exercise. Cloud VPC route tables are static routes. The internet backbone runs on dynamic routing (BGP). Your home router uses a single static default route pointing to your ISP. Data center networks use dynamic routing protocols (OSPF, BGP) to handle failover automatically. The right choice depends on the network's size, redundancy requirements, and how much change the network experiences.

Static Routing

Static routing means a network administrator manually enters routes into the routing table. Each route specifies a destination network, a next-hop address, and optionally an outgoing interface. Static routes do not change unless the administrator changes them - they are permanent, fixed, and deterministic.

A simple static route configuration on a Linux machine:

# Add a static route: traffic for 10.0.2.0/24 goes via 10.0.1.1
ip route add 10.0.2.0/24 via 10.0.1.1

# Add a default route: all unknown destinations go via 192.168.1.1
ip route add default via 192.168.1.1

# View current routes
ip route show

On a Cisco router, the equivalent commands would be:

# Static route: destination 10.0.2.0/24, next-hop 10.0.1.1
ip route 10.0.2.0 255.255.255.0 10.0.1.1

# Default route
ip route 0.0.0.0 0.0.0.0 192.168.1.1

When Static Routing Works Well

Static routing is the right choice in specific situations:

Small networks with simple topologies. A network with 3-5 routers and no redundant paths has a finite number of routes that can be configured manually in minutes. The simplicity of static routes - no protocol overhead, no convergence delay, no routing update traffic - makes them ideal for small environments.

Stub networks. A stub network has only one connection to the rest of the network. A branch office with a single WAN link to headquarters needs only one route: the default route pointing to headquarters. There are no alternative paths, so dynamic routing adds complexity without benefit.

Cloud VPC route tables. AWS, GCP, and Azure route tables are fundamentally static routes. When you add a route saying "10.0.0.0/8 via transit gateway," you are creating a static route. Cloud providers use this approach because VPC topologies change infrequently and changes are managed through infrastructure-as-code, not routing protocols.

Security-sensitive paths. Static routes are predictable and cannot be manipulated by a compromised routing protocol. Some organizations use static routes for traffic that must follow a specific path through security appliances or inspection points.

Where Static Routing Fails

No automatic failover. If the next-hop router goes down, the static route continues pointing to it. Traffic is sent to a dead next hop and black-holed until an administrator manually updates the route. This makes static routing unsuitable for networks that need high availability without human intervention.

Does not scale. A network with 100 routers and thousands of subnets would require manually configuring and maintaining thousands of routes across dozens of devices. Any topology change - adding a subnet, moving a server, replacing a router - requires manual updates on every affected device. This operational burden becomes untenable at scale.

No load balancing across paths. If two paths exist between two networks, static routing cannot automatically distribute traffic across both. You can configure two static routes with equal metrics, but this is manual and inflexible compared to dynamic routing's automatic load balancing.

graph TD
    subgraph StaticRouting["Static Routing"]
        direction TB
        ADMIN["Administrator<br/>manually configures<br/>routes"] --> RT["Routing Table<br/>(fixed until<br/>manually changed)"]
        RT --> FWD["Forwarding<br/>decisions"]
        FAIL["Link failure"] -.->|"No automatic<br/>update"| RT
    end

    subgraph DynamicRouting["Dynamic Routing"]
        direction TB
        PROTO["Routing Protocol<br/>(OSPF, BGP, RIP)<br/>automatically discovers<br/>network topology"] --> RT2["Routing Table<br/>(updates when<br/>topology changes)"]
        RT2 --> FWD2["Forwarding<br/>decisions"]
        FAIL2["Link failure"] -->|"Protocol detects,<br/>recalculates routes"| RT2
    end

    style ADMIN fill:#4f46e5,stroke:#4338ca,color:#fff
    style RT fill:#7c3aed,stroke:#6d28d9,color:#fff
    style FWD fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style FAIL fill:#ef4444,stroke:#dc2626,color:#fff
    style PROTO fill:#4f46e5,stroke:#4338ca,color:#fff
    style RT2 fill:#7c3aed,stroke:#6d28d9,color:#fff
    style FWD2 fill:#8b5cf6,stroke:#7c3aed,color:#fff
    style FAIL2 fill:#22c55e,stroke:#16a34a,color:#fff
This diagram contrasts static and dynamic routing. In static routing, an administrator manually configures routes into the routing table, which stays fixed until manually changed. When a link fails, there is no automatic update - traffic continues being sent to the dead path. In dynamic routing, a routing protocol like OSPF or BGP automatically discovers the network topology and builds the routing table. When a link fails, the protocol detects the failure and recalculates routes, automatically redirecting traffic around the problem.

Dynamic Routing

Dynamic routing uses protocols that run on routers to automatically discover network topology, compute optimal paths, and adapt when the topology changes. Routers exchange routing information with their neighbors, and each router independently computes the best path to every known destination based on the collective information.

The key advantages of dynamic routing are automatic failover, scalability, and adaptability. When a link fails, routers detect the failure, recalculate paths, and converge on a new topology - typically within seconds to minutes, depending on the protocol. When a new network is added, neighboring routers learn about it automatically and propagate the information throughout the network. No human intervention is required for routine topology changes.

How Dynamic Routing Protocols Detect Failures

Dynamic routing protocols detect link and router failures through two mechanisms:

Hello messages. Most protocols send periodic hello packets to their neighbors. If a router stops receiving hellos from a neighbor (typically after missing 3-4 consecutive hellos), it declares the neighbor down and triggers a route recalculation. OSPF default hello interval is 10 seconds with a 40-second dead timer. BFD (Bidirectional Forwarding Detection) can detect failures in milliseconds for environments that need sub-second failover.

Interface state changes. When a physical interface goes down (cable unplugged, optic fails), the router immediately knows without waiting for hello timeouts. This triggers instant route recalculation for any routes that depend on that interface.

Routing Metrics

Every dynamic routing protocol uses a metric to quantify the "cost" of reaching a destination. When multiple paths exist, the path with the lowest metric wins:

Protocol Metric What It Measures
RIP Hop count Number of routers between source and destination
OSPF Cost Typically based on link bandwidth (higher bandwidth = lower cost)
EIGRP Composite Bandwidth, delay, reliability, load (configurable weights)
BGP Path attributes AS path length, local preference, MED, and many policy-based attributes

RIP's hop count metric is crude - it treats a 10 Gbps fiber link the same as a 1 Mbps DSL link. OSPF's bandwidth-based cost is more intelligent - it naturally prefers faster links. This difference in metric sophistication is one reason OSPF replaced RIP in most networks.

Categories of Dynamic Routing Protocols

Dynamic routing protocols fall into three major categories based on how they compute paths:

Distance Vector protocols (RIP, EIGRP) work like asking neighbors for directions. Each router knows the distance (number of hops or other metric) to each destination and shares this information with its directly connected neighbors. Routers learn about distant networks only through what their neighbors tell them - they do not have a complete picture of the network topology. The Bellman-Ford algorithm underpins distance vector protocols.

Link-State protocols (OSPF, IS-IS) work like building a complete map. Each router discovers its directly connected neighbors and the cost of each link, then floods this information to every other router in the network. Every router ends up with a complete, identical map of the network topology, and each independently runs Dijkstra's algorithm to compute the shortest path to every destination. Link-state protocols converge faster and are more resistant to routing loops than distance vector protocols.

Path Vector protocols (BGP) are used between autonomous systems (organizations). Each route advertisement carries the complete path of autonomous systems that the route has traversed. This prevents routing loops (a router rejects any path that includes its own AS number) and allows complex policy-based routing decisions. BGP is the only routing protocol used for inter-domain routing on the internet.

Convergence

Convergence is the process by which all routers in a network agree on a consistent view of the topology after a change occurs. When a link fails, routers detect the failure, propagate the information, recalculate paths, and update their forwarding tables. The time this takes - the convergence time - directly impacts network availability.

Fast convergence means brief disruptions. Slow convergence means extended periods where some routers have stale information and send traffic down dead paths. Modern link-state protocols like OSPF can converge in under a second with tuned timers. Older distance vector protocols like RIP may take minutes to converge, during which time the network may experience routing loops and packet loss.

Convergence speed is one of the primary reasons link-state protocols replaced distance vector protocols in most enterprise and service provider networks. The internet's BGP convergence is notably slower - a major BGP route change can take minutes to propagate globally - which is why BGP incidents can cause extended outages affecting millions of users.

The importance of convergence cannot be overstated. During convergence, the network is in an inconsistent state: some routers have updated their forwarding tables while others still hold stale routes. Packets may be dropped, looped, or sent down suboptimal paths during this window. Reducing convergence time is one of the most important goals in network design - it directly determines how long users experience outages when failures occur. Technologies like BFD (sub-second failure detection), OSPF fast-hello (sub-second hello intervals), and BGP graceful restart all exist to minimize convergence time in different contexts.

graph TD
    subgraph Categories["Dynamic Routing Protocol Categories"]
        direction TB
        DV["Distance Vector<br/>(RIP, EIGRP)<br/>Share distance to destinations<br/>with neighbors only<br/>Bellman-Ford algorithm"]
        LS["Link-State<br/>(OSPF, IS-IS)<br/>Flood complete topology<br/>to all routers<br/>Dijkstra's algorithm"]
        PV["Path Vector<br/>(BGP)<br/>Share full AS path<br/>for inter-domain routing<br/>Policy-based decisions"]
    end

    style DV fill:#4f46e5,stroke:#4338ca,color:#fff
    style LS fill:#7c3aed,stroke:#6d28d9,color:#fff
    style PV fill:#8b5cf6,stroke:#7c3aed,color:#fff
This diagram shows the three categories of dynamic routing protocols. Distance vector protocols like RIP and EIGRP share distance information with neighbors only and use the Bellman-Ford algorithm. Link-state protocols like OSPF and IS-IS flood complete topology information to all routers and use Dijkstra's algorithm. Path vector protocols, specifically BGP, share the full autonomous system path for inter-domain routing and support policy-based routing decisions.

Choosing Between Static and Dynamic

The decision is not binary - most real networks use both. The question is which approach dominates for each part of the network.

Real-World Examples

Home network: Your home router has a single static default route pointing to your ISP. There is only one path to the internet, so dynamic routing would add complexity with zero benefit.

Small office (5-10 employees): A single router with static routes to internal subnets and a default route to the ISP. If the office grows to multiple buildings or adds a backup internet connection, dynamic routing starts making sense.

Enterprise campus (hundreds of switches and routers): OSPF handles internal routing automatically. Adding a new building or subnet requires configuring OSPF on the new router - all existing routers learn the new routes automatically within seconds. Static routes handle specific policy paths (e.g., traffic to the security DMZ must pass through the firewall).

Cloud-native application: VPC route tables use static routes for internal traffic. BGP runs between the VPC and on-premises networks via Direct Connect or VPN, enabling automatic failover between primary and backup connections. The application does not need to know about routing - the infrastructure handles it.

The internet: Entirely dynamic routing using BGP between autonomous systems and OSPF/IS-IS within each autonomous system. The internet has approximately 1 million BGP routes - managing these statically would be impossible.

Criterion Static Dynamic
Network size Small (< 10 routers) Medium to large
Redundant paths None or few Multiple alternative paths
Change frequency Rarely changes Frequent additions/removals
Failover requirement Manual failover acceptable Automatic failover required
Operational staff Limited networking expertise Dedicated network engineers
Protocol overhead Zero Routing updates consume bandwidth and CPU
Security Predictable, tamper-resistant Vulnerable to route injection attacks
Cloud VPCs Default approach Rare (some use BGP with transit gateways)

Hybrid pattern: Many enterprise networks use OSPF for internal dynamic routing (within their own network) while also maintaining static routes for specific paths that must follow a fixed route - such as traffic that must pass through a firewall or inspection appliance. Cloud networks often combine static VPC routes with BGP for connections to on-premises networks via Direct Connect or VPN gateways.

Interview: Routing decisions appear in cloud architecture discussions:

"How do you handle failover between two data centers?" - Dynamic routing (BGP) between the data centers and the internet, so traffic automatically shifts to the healthy data center when one fails. Within each data center, OSPF handles internal routing and reconverges if an internal link fails.

"Why not just use static routes everywhere?" - Static routes do not detect failures. If the next hop dies, traffic is black-holed until someone manually intervenes. At scale, this means every link failure becomes a page-the-engineer incident instead of an automatic recovery.

"What routing does your VPC use?" - Static routes in the VPC route table for most traffic. BGP via a Virtual Private Gateway or Transit Gateway for the connection to on-premises networks, enabling automatic failover between primary and backup VPN tunnels.

What Comes Next

The next topic dives into the first dynamic routing protocol: RIP (Routing Information Protocol), a distance vector protocol that uses the Bellman-Ford algorithm. RIP is largely historical - modern networks rarely use it - but understanding its design, its limitations, and the count-to-infinity problem it suffers from provides essential context for understanding why link-state protocols like OSPF replaced it.

Exercise: Starter: View your machine's routing table (ip route show on Linux, netstat -rn on Mac, route print on Windows). Every entry is a static route. How many routes do you have? What is the default route's next hop? Are any routes pointing to specific subnets rather than the default?

Intermediate: If you have access to AWS, examine the route table for a VPC subnet. Add a custom static route (e.g., 10.99.0.0/16 pointing to a blackhole - a safe way to experiment without affecting real traffic). Observe how the route table updates. Delete the route afterward. How does this process compare to configuring routes on a physical router?

Advanced: Research the concept of "floating static routes" - static routes configured with a higher administrative distance than dynamic routes. They remain in the routing table as backups: if the dynamic route disappears (the routing protocol loses the path), the static route takes over. This is a common pattern for backup paths in enterprise networks. How would you implement this in a cloud environment?

Back to Computer Networking