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).

  • 1
    Aah, yes, per the answer... ifconfig and its subinterfaces are pretty much obsolete now, in favour of iproute2. – Falcon Momot Nov 18 '14 at 8:58
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
| improve this answer | |
  • As simple as that! I had not realised the power of the ip command. Thanks – Antony Gibbs Nov 18 '14 at 2:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.