How to use eth1 as failsafe system for eth0?

Solution 1:

What you are looking to set up is called Network Bonding.

This is also called "port trunking or link aggregation (which) means combining several network interfaces (NICs) to a single link, providing either high-availability, load-balancing, maximum throughput, or a combination of these."

In this case, you will want to set up a Mode 1 active-backup bonding configuration.

  1. Install package to allowing interface bonding**

    • First, you will need to install the ifenslave package which allows interfaces to be added and removed from a bonding group.

    • Install the ifenslave package from the Ubuntu Software Center:

    Install via the software center

    • or, you can install the package from the command line:

      sudo apt-get install ifenslave-2.6

  2. Modify config to load bonding module

    Next, you will modify your /etc/modules file to ensure that the bonding module is loaded.

    sudo gedit /etc/modules and add the following line to the bottom of the file:

    bonding mode=active-backup miimon=100 max_bonds=2 primary=eth0
    

    The miimon option tells how often to monitor(in milliseconds) the interface for failure and can be adjusted as needed.

  3. load the bonding kernel module:

    sudo modprobe bonding
    
  4. Define the bond group

    Finally, you will define the bond group in the file /etc/network/interfaces and restart the networking service.

    sudo gedit /etc/network/interfaces/

    auto bond0
      iface bond0 inet static
        address 192.168.1.10
        gateway 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
        broadcast 192.168.1.255
        bond-slaves none
        bond-mode 1
        bond-miimon 100
        post-up ifenslave bond0 eth0 eth1
        pre-down ifenslave -d bond0 eth0 eth1
    
    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
    
  5. Restart the networking service

    sudo service networking restart

Note: This does not allow for bonding between two different network types (i.e. You cannot bond between an ethernet card and a wireless connection.)

Also, this has nothing to do with multi-homing between two ISPs and is beyond the scope of this question.

References:

https://help.ubuntu.com/community/UbuntuBonding#Ethernet_Bonding_modes

http://ubuntuforums.org/showthread.php?t=1888967

http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-modules-ethernet.html#s3-modules-bonding-directives

Solution 2:

You need network bonding.

From https://help.ubuntu.com/community/UbuntuBonding:

Bonding, also called port trunking or link aggregation means combining several network interfaces (NICs) to a single link, providing either high-availability, load-balancing, maximum throughput, or a combination of these.

Install ifenslave (sudo apt-get install ifenslave-2.6), and configure /etc/network/interfaces like this:

auto eth0
iface eth0 inet manual

auto eth1
iface eth1 inet manual

auto bond0
iface bond0 inet static
       address 192.168.0.1
       netmask 255.255.255.0
       gateway 192.168.0.254
       slaves eth0 eth1
       bond-mode active-backup