1

My system has 2 interfaces (eth0, eth1).
I open a socket and bind it with an ip attached to eth0, now I want the OS to route the packets to another ip (which attached to eth1 but i'm not sure it's important) in case eth0 is down.
Is there a way of knowing when an interface is down and re-route its source packets through another ip ?

3
  • So you wanna have redundant NICs essentially? Commented Aug 6, 2015 at 2:03
  • @Creek I already have it, I choose not to use it but in case the first is down Commented Aug 6, 2015 at 7:21
  • @SagiLow If you don't want to use bonding like mentioned below build the logic into the application or scale horizontally into 2 hosts for redundancy Commented Aug 7, 2015 at 1:10

2 Answers 2

2

It sounds like you want to use the bonding driver. This will use one of your interfaces and, if it goes down, it will jump to the other one.

I would try changing the /etc/network/interfaces to something like this:

auto bond0
iface bond0 inet dhcp
    bond-slaves none
    bond-mode active-backup
    bond-miimon 100

auto eth0
iface eth0 inet manual
    bond-master bond0
    bond-primary eth0 eth1

auto eth1
iface eth1 inet manual
    bond-master bond0
    bond-primary eth0 eth1
4
  • I'm not sure bound will do, can I select to which interface to bind when I create a socket ? (I always want to give priority to eth0 if it's up Commented Aug 5, 2015 at 20:54
  • The idea is that you use the bond0 interface and it shouldn't matter if eth0 or eth1 is the active one. If you want to force the mac in eth0 and make eth0 the selected interface, you can delay eth1 as suggested here: ubuntuforums.org/showthread.php?t=1967987. For more advanced options please read the documentation. Commented Aug 5, 2015 at 21:38
  • Thank you, unfortunately delaying one cannot guarantee what I want (it's a race between the two). And I understand the idea of a bond (which means it doesn't matter if eth0 or eth1 is active) this is exactly why bond isn't the right solution here. I have to be able to try using eth0 and use eth1 only in case it fails. Commented Aug 5, 2015 at 21:42
  • OK, I'm not an expert but I believe that bonding could do that, sorry I cannot give more info about it. Commented Aug 5, 2015 at 21:45
0

I've managed to work this out using the following explanation :

Using a Linux failover router
http://archive09.linux.com/articles/113988

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.