In this lesson, you will learn how to prevent asymmetric routing and catastrophic routing loops when your Linux host is connected to two or more independent internet uplinks.
The Problem: The "Return Path" Trap
When a host is "multi-homed" (connected to two ISPs, for instance), the kernel faces a dilemma: if a packet arrives on eth1, should the reply necessarily go back out through eth1? By default, the Linux kernel relies on a single main routing table. If your default gateway points to eth0, all outgoing traffic—even replies to traffic that arrived on eth1—will attempt to exit via eth0.
This is not only an asymmetric routing nightmare, but in many environments, it triggers Reverse Path Filtering (RPF). If your ISP detects a packet with a source IP belonging to their network arriving from an "upstream" interface that doesn't match their routing expectations, they may drop the packet, or your own kernel might drop it to prevent spoofing.
Solving it with Policy-Based Routing
To prevent loops and ensure traffic symmetry, we decouple the routing decisions from a single global table. We create specific routing tables for each interface and use Policy-Based Routing (PBR) to ensure traffic follows the "path of least resistance" based on its origin.
Implementation Logic
Instead of relying on the main table, use the ip rule command to force traffic to a specific table based on the source IP:
# Create a dedicated table for ISP2
echo "200 isp2_table" >> /etc/iproute2/rt_tables
# Ensure traffic originating from ISP2's IP uses the isp2_table
ip rule add from 192.168.2.50 table isp2_table
# Add a default route specifically for that table
ip route add default via 192.168.2.1 dev eth1 table isp2_table
By ensuring that packets arriving on an interface are answered via that same interface's routing table, you eliminate the ambiguity that causes routing loops. The kernel no longer has to "guess" the exit path; it looks at the source address of the packet and selects the table that matches the interface's unique gateway, keeping the traffic flow consistent and predictable.
Key Takeaway: Multi-homed stability requires source-based routing policies that ensure outbound responses exit through the same interface that received the initial request.