At the point your host is making the relevant routing decision, the input interface (iif
in your rule) is the bridge device, not viifv1424
.
Example setup
On my system, I'm running a typical libvirt setup. I have a network default
associated with bridge device virbr0
. If I create a virtual machine on that network, the virtual machine gets attached to virtual interface vnet0
.
I have a wireguard interface configured as wg0
, with address 192.168.64.14
.
Rules that don't work
If I set up the equivalent to your rules:
ip route add default dev wg0 table 100
ip rule add prio 100 iif vnet0 table 100
iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
And then attempt to ping 8.8.8.8
, I see the echo request go out the host default interface.
Rules that do work
If instead I set up the policy rule with the bridge interface as the input interface:
ip route add default dev wg0 table 100
ip rule add prio 100 iif virbr0 table 100
iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
Then I see the request go out wg0
as desired. Running tcpdump -i wg0 -n
I see:
19:05:19.217001 IP 192.168.64.14 > 8.8.8.8: ICMP echo request, id 26, seq 1, length 64
19:05:19.274453 IP 8.8.8.8 > 192.168.64.14: ICMP echo reply, id 26, seq 1, length 64