Source-based routing across two Linux uplinks

Use separate routing tables so replies leave through the intended provider.

With one default route, a host may answer a connection from the second provider through the first. Source-based policy rules send replies from each public address through the matching uplink.

Example network

eth0  203.0.113.10/29  gateway 203.0.113.9   (ISP-A, primary)
eth1  198.51.100.20/28 gateway 198.51.100.17 (ISP-B)

Routing tables and rules

echo "101 ispa" >> /etc/iproute2/rt_tables
echo "102 ispb" >> /etc/iproute2/rt_tables

ip route add 203.0.113.8/29 dev eth0 src 203.0.113.10 table ispa
ip route add default via 203.0.113.9 table ispa
ip route add 198.51.100.16/28 dev eth1 src 198.51.100.20 table ispb
ip route add default via 198.51.100.17 table ispb

ip rule add from 203.0.113.10 table ispa priority 1000
ip rule add from 198.51.100.20 table ispb priority 1001

Traffic sourced from the address on eth1 uses the ISP-B table. Replies from 198.51.100.20 should leave through that link.

Reverse-path filtering

If incoming traffic is still dropped, check net.ipv4.conf.all.rp_filter. Strict reverse-path filtering checks that the best route back matches the incoming interface. A multi-uplink arrangement can require loose mode.

sysctl -w net.ipv4.conf.all.rp_filter=2
sysctl -w net.ipv4.conf.eth1.rp_filter=2

Persist the configuration

With systemd-networkd, use [RoutingPolicyRule] and a Table= setting in [Route]. With Netplan, define routing-policy and a table for the relevant route.

Run ip route get 1.1.1.1 from 198.51.100.20. The result should include via 198.51.100.17 dev eth1 table ispb.