KEEPALIVED_INTERFACE instead of eth0, can you default to the default gw one? $(ip route | grep default | head -1 | cut -d" " -f5) I think this would cover most of the cases.