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

  linux, question

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

iface eth0:1 inet static
 address  123.123.123.1
 netmask 255.255.255.0
 gateway  123.123.123.100
 
 iface eth0:2 inet static
 address  123.123.123.2
 netmask 255.255.255.0

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  123.123.123.100 dev eth1 src  123.123.123.2 table 100
 ip ro add default dev eth1 table 100
 ip ru add from  123.123.123.2 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?