I'm using iptables to forward and SRCNAT (specifically MASQUERADE) packets from a specific source. I want to route outgoing packets (initiated by this computer) differently from those being forwarded (different default route). How do I do this?
Route forwarded packets differently from outgoing
iptables;routing;iproute
One way is to mark the traffic in iptables and match an outbound route with policy routing:let's say you have gateway1 and gateway2 on the same LAN...ip route flush table 3ip route add table 3 <lan net>ip route add default via <gateway1>ip route flush table 4ip route add table 4 <lan net>ip route add default via <gateway2>Tag the traffic in iptables:iptables -t mangle -A PREROUTING   -s 10.0.0.0/24 -j MARK --set-mark 3iptables -t mangle -A PREROUTING   -s 10.1.0.0/24 -j MARK --set-mark 4You can match on anything you like, source address, destination address or port, etc...Since you're explicitly rewriting the source IP in iptables rather than relying on a dynamic gateway IP you probably want to use SNAT instead of MASQUERADE.  See Differences between SNAT and MASQUERADE