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 ?
-
So you wanna have redundant NICs essentially?Creek– Creek2015-08-06 02:03:29 +00:00Commented Aug 6, 2015 at 2:03
-
@Creek I already have it, I choose not to use it but in case the first is downSagiLow– SagiLow2015-08-06 07:21:50 +00:00Commented 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 redundancyCreek– Creek2015-08-07 01:10:16 +00:00Commented Aug 7, 2015 at 1:10
Add a comment
|
2 Answers
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
-
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
eth0if it's upSagiLow– SagiLow2015-08-05 20:54:40 +00:00Commented 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.Katu– Katu2015-08-05 21:38:50 +00:00Commented 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.SagiLow– SagiLow2015-08-05 21:42:04 +00:00Commented 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.Katu– Katu2015-08-05 21:45:04 +00:00Commented Aug 5, 2015 at 21:45
I've managed to work this out using the following explanation :
Using a Linux failover router
http://archive09.linux.com/articles/113988