I have 10.1.1.1 and 10.2.2.2 bound to eth0.
# ip address show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 04:01:05:ff:42:01 brd ff:ff:ff:ff:ff:ff
inet 10.2.2.2/24 brd 10.2.2.255 scope global eth0
inet 10.1.1.1/32 scope global eth0
inet6 fe80::601:5ff:feff:4201/64 scope link
valid_lft forever preferred_lft forever
# ip route get 10.1.1.1
local 10.1.1.1 dev lo src 10.1.1.1
Question A: why does it use "dev lo" when the IP is bound to eth0?
I want to force local connections to 10.1.1.1 to have a source address of 10.2.2.2. So I try:
# ip route add 10.1.1.1/32 dev eth0 src 10.2.2.2
# ip route show
default via 10.2.2.1 dev eth0
10.1.1.1 dev eth0 scope link src 10.2.2.2
10.2.2.0/24 dev eth0 proto kernel scope link src 10.2.2.2
# ip route get 10.1.1.1
local 10.1.1.1 dev lo src 10.1.1.1
Question B: How do I override this strange "local" route?
Background: the packets are intercepted by the IPVS kernel subsystem. Before it gets there, I need the correct source address, otherwise IPVS doesn't know what to do with it. SNATting with iptables doesn't work, as that happens in the POSTROUTING phase, and IPVS skips that. See also my related question at Linux IPVS in DR mode: VIP unreachable for director
Thanks!