0

I have a server with multiple interface alias running debian. lets say eth0 eth0:0 and eth0:1

I'm looking for a simple solution, when connecting to host 1.2.3.4 (or host range, would be better) that I could enforce using ip address of eth0:1 (and not eth0 as it does by default) to access some external services that are open to only that ip on eth0:1 (eth0:1 is a ovh 'failover ip', it can be moved to a different server during maintenance tasks).

Falcon Momot
  • 25,244
  • 15
  • 63
  • 92
Antony Gibbs
  • 515
  • 3
  • 12

1 Answers1

4

Let's say your host has IP addresses 10.0.0.2 and 10.0.0.3 and your default gateway is 10.0.0.1. Now if you want to use different local IP addresses to communicate with remote addresses 10.2.2.2 and 10.3.3.3, you could do like this:

ip route add 10.2.2.2/32 via 10.0.0.1 src 10.0.0.2
ip route add 10.3.3.3/32 via 10.0.0.1 src 10.0.0.3
kasperd
  • 30,455
  • 17
  • 76
  • 124