For ages(>7yr) my automation scripts were adding new external IPs to the servers in this way
ifconfig lo:0 126.96.36.199 netmask 255.255.255.255 ifconfig lo:1 188.8.131.52 netmask 255.255.255.255 ...
This worked fine with all (>10) providers i worked with and i never had problems.
Now i realized, that i was adding ips to loopback and it might be wrong
and lo just left after playing in 127.0.0.0/8 sandbox =)
A short investigation figured out, that necessary route adds automatically and packet arrived to these ips is routed correctly
lo route is visible in routel as
184.108.40.206 local 220.127.116.11 kernel host lo local 18.104.22.168 local 22.214.171.124 kernel host lo local
but not in ip route show
default via 126.96.36.199 dev eth0 188.8.131.52/24 dev eth0 proto kernel scope link src 184.108.40.206
Testing a route: sends via default route to server`s basic (added to eth0) ip gateway
#ip route get 220.127.116.11 from 18.104.22.168 iif lo 22.214.171.124 from 126.96.36.199 via 188.8.131.52 dev eth0
So, im sending packets from 184.108.40.206 to 192.168.1.1 instead of 220.127.116.11 and it works on MANY configurations with no questions asked by MANY providers.
Q1: Why is this working?
Q2: Which way of adding multiple gateways is better?(18.104.22.168 for source 22.214.171.124, 126.96.36.199 for source 188.8.131.52)
is adding multiple like below a good idea or src based routing is better?
auto eth0:0 iface eth0:0 inet static address 184.108.40.206 netmask 255.255.255.0 broadcast 220.127.116.11 gateway 18.104.22.168 auto eth0:1 iface eth0:1 inet static address 22.214.171.124 netmask 255.255.255.0 broadcast 126.96.36.199 gateway 188.8.131.52
Thanks for help!