For ages(>7yr) my automation scripts were adding new external IPs to the servers in this way
ifconfig lo:0 11.22.99.44 netmask 255.255.255.255
ifconfig lo:1 11.22.33.44 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
11.22.33.44 local 11.22.33.44 kernel host lo local
11.22.99.44 local 11.22.33.44 kernel host lo local
but not in ip route show
default via 99.88.22.1 dev eth0
99.88.22.0/24 dev eth0 proto kernel scope link src 99.88.22.123
Testing a route: sends via default route to server`s basic (added to eth0) ip gateway
#ip route get 5.5.5.5 from 11.22.33.44 iif lo
5.5.5.5 from 11.22.33.44 via 99.88.22.1 dev eth0
So, im sending packets from 11.22.33.44 to 192.168.1.1 instead of 11.22.33.1 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?(11.22.99.1 for source 11.22.99.44, 11.22.33.1 for source 11.22.33.44)
is adding multiple like below a good idea or src based routing is better?
auto eth0:0
iface eth0:0 inet static
address 11.22.33.44
netmask 255.255.255.0
broadcast 11.22.33.255
gateway 11.22.33.1
auto eth0:1
iface eth0:1 inet static
address 11.22.99.44
netmask 255.255.255.0
broadcast 11.22.99.255
gateway 11.22.99.1
Thanks for help!