In this lesson, you will learn how to configure the Linux kernel to automatically detect a failed network path and shift traffic to an operational alternative at the IP level.
Understanding Path Failover
When your server is connected to multiple upstream routers or ISPs, you need a mechanism to ensure traffic flows through an active path. If a gateway becomes unreachable, static routes stay active in the kernel table, leading to "black-holing" your data. To solve this, we use the ip route command combined with nexthop objects to implement automated failover.
Implementing Active-Backup Routing
Modern Linux kernels allow you to define a multipath route with specific priorities or weights. By monitoring a gateway's reachability, we can instruct the kernel to ignore a failed interface and promote the backup path to the active state.
Instead of traditional bonding, which operates at Layer 2, we use Layer 3 routing attributes. You can configure a route with multiple nexthops that the kernel monitors. If the primary nexthop fails, the kernel removes it from the routing cache, and traffic automatically cascades to the secondary nexthop.
Here is how you define a primary and backup route using ip route:
# Set up a multipath route with a primary and a backup gateway
ip route add default \
nexthop via 192.168.1.1 dev eth0 weight 1 \
nexthop via 192.168.2.1 dev eth1 weight 1
To make this failover intelligent, administrators typically use a background daemon or a script that watches the state of these routes. When the kernel detects that the link to 192.168.1.1 is down—often triggered by periodic ARP requests or ICMP probes—it stops selecting that nexthop for packet encapsulation. Once the path is marked as dead, the kernel routing stack immediately selects the next available nexthop in the list, ensuring that your application-layer connections survive the transition without manual intervention.
By leveraging these kernel-level routing primitives, you create a robust network architecture that recovers from link failures in milliseconds, maintaining connectivity even when your primary circuit experiences a total outage.
Key Takeaway: Automated path failover at the IP level is achieved by configuring multiple nexthops within a single routing entry, allowing the kernel to transparently switch to an available path when a gateway becomes unresponsive.