Skip to content

rp_filter silently drops replies: asymmetric routing on Linux

Networkingtested on Ubuntu 24.04, iproute2, Policy Routing mit zwei Uplinks

The capture shows the reply at the router, nothing arrives at the sender, and there is no error message anywhere. That is the signature of reverse path filtering: in strict mode the kernel drops packets whose return path would leave through another interface.

Symptom

sudo ip netns exec r sysctl -w net.ipv4.conf.all.rp_filter=1 net.ipv4.conf.up1.rp_filter=1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.up1.rp_filter = 1
sudo ip netns exec c2 ping -c2 -W1 198.51.100.1 | grep -o '[0-9] received'
0 received

In the course one provider now sends the replies back over the other uplink, and a colleague set rp_filter to strict for hardening.

Diagnosis

Does the reply reach the router? A capture on the incoming interface shows it.

sudo ip netns exec r tcpdump -ni up1 icmp
19:43:07.157646 IP 198.51.100.1 > 10.40.2.20: ICMP echo reply, id 5672, seq 1, length 64

Causes

TcpExtIPReversePathFilterReverse path filtering drops the packets

The kernel counts every drop – despite Tcp in the name, for all protocols.

sudo ip netns exec r nstat -az TcpExtIPReversePathFilter
#kernel
TcpExtIPReversePathFilter       3                  0.0

return via up2The return path leaves through another interface

The reply arrives on up1, but the way back to the sender leads over up2. Strict (1) demands the same interface, loose (2) only some way back.

sudo ip netns exec r ip route get 198.51.100.1 from 10.40.2.20 iif eth2
198.51.100.1 from 10.40.2.20 via 10.42.0.1 dev up2 table isp2
    cache iif eth2

all and interfaceThe higher value wins

Per interface the kernel uses the higher value of conf.all and conf.INTERFACE. Setting only all to 1 changed nothing in the course, because up1 was at 2.

Fix

Switch to loose checking (2) – on all and on the interface – and test again.
sudo ip netns exec r sysctl -w net.ipv4.conf.up1.rp_filter=2 net.ipv4.conf.all.rp_filter=2
net.ipv4.conf.up1.rp_filter = 2
net.ipv4.conf.all.rp_filter = 2
sudo ip netns exec c2 ping -c2 -W1 198.51.100.1 | grep -o '[0-9] received'
2 received

Don't: Setting rp_filter to 0 everywhere. Loose (2) allows asymmetric routing and still protects against senders with no return path at all.

▶
Break it yourself and find it – free
Linux networking hands-on, Day 4: routing, policy routing with two providers, VRFs and rp_filter.
Go to day 4 →

FAQ

Which values does rp_filter know?

0 off, 1 strict (return path over the same interface), 2 loose (any return path). Ubuntu sets new interfaces to 2.

Where do I see that rp_filter struck?

In the TcpExtIPReversePathFilter counter, with nstat -az TcpExtIPReversePathFilter in the affected namespace or host.

Related error patterns

More