Different gateways for different IPs on same interface on Linux

clustergatewaylinux-networkingpolicy-routingrhel7

I have the following question:

considering the attached image:
Schema

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

  • 192.168.10.1 (eth0, server address on network 192.168.10.0/24)
  • 192.168.10.100 (eth0:1, a cluster resource's virtual IP on network 192.168.10.0/24)
  • 192.168.20.100 (eth0:2, a cluster resource's virtual IP on network 192.168.20.0/24)

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 192.168.10.254 dev eth1  table admin
192.168.10.0/24 dev eth1  table admin  scope link  src 192.168.10.100
default via 192.168.20.254 dev eth0
192.168.20.0/24 dev eth0  proto kernel  scope link  src 192.168.20.100
192.168.10.0/24 dev eth1  proto kernel  scope link  src 192.168.10.100

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