Different gateways for different IPs on same interface on Linux


I have the following question:

considering the attached image:

I have a server (RHEL 7) with 3 IP addresses (on the same physical interface):

  • (eth0, server address on network
  • (eth0:1, a cluster resource's virtual IP on network
  • (eth0:2, a cluster resource's virtual IP on network

Since the two cluster resources are on two different networks, I must be sure that, for each client request to one of the resources, the path of the responses remains exactly the same. This means using the two different gateways on the basis on the resources' IP addresses.

Is source policy routing with iproute2 the right way to achieve this?

Thanks in advance,

Best Answer

Right. Basically, it should look like this (from the working system with two ethernet links):

admin@mamba:~$ ip route show table all
default via dev eth1  table admin dev eth1  table admin  scope link  src
default via dev eth0 dev eth0  proto kernel  scope link  src dev eth1  proto kernel  scope link  src

admin@mamba:~$ ip rule show
0:      from all lookup local
32764:  from all to lookup admin
32765:  from lookup admin
32766:  from all lookup main
32767:  from all lookup default