Routing based on the source ip

I'm trying to configure a host in a way that the traffic is routed either via eth0 or vlan123@eth0, depending on the source address used. Both interfaces have access to the whole network and both have some ip assigned.

For example: eth0 has 1.2.3.1/24 and vlan123 has 4.5.6.1/24. The default gateway is set via eth0. How can I make sure that if:

  • packet comes in to 1.2.3.1 (will arrive untagged), the response will be sent to eth0
  • packet comes in to 4.5.6.1 (will arrive 802.1q tagged), the response will be sent to vlan123

Is it possible without additional routing protocols? (for example forcing via iptables)


Look for information on "policy routing". The particular use case you're looking at is covered in the Advanced Routing and Traffic Control HOWTO, as well as elsewhere.