Linux Single Network Card Single Gateway Double ip, How to Return Data to Its Original Path?

  linux, question

Now there is IPA: IPB: Gateway:
Apache is bound to ipA and another java program is bound to ipB.
Network configuration

iface eth0:1 inet static
 iface eth0:2 inet static

Now the data is normal after coming in from ipA, but the data coming in from ipB is also identified as ipA by default, which results in the original users accessing with ipB not receiving the data.
In order to solve the problem temporarily, connect the network cable of the second network card, set the second network card as ipB, and then enter the following command

ip ro add dev eth1 src table 100
 ip ro add default dev eth1 table 100
 ip ru add from table 100

The two services can be accessed normally, but the solution is too good to know what the correct approach should be.

Are you sure there is no problem with your network configuration? Under normal circumstances, a packet will not be changed from src ip. is there no configuration such as iptables?