1

I started My project using a raspberry Pi 2 model B and installed Fedora Arm on it. My current Goal is to be able to connect the pi to internet through an ethernet cable connected to a DSL router aswell as a 3G usb dongle in a way where I can set up a fail over mechanic. To do so I figured I need to make a script that checks if eth0 (ethernet connection) is working by issuing ping 8.8.8.8 -I eth0, if it isn't working I can switch to the 3G connection by taking down the eth0, and activating eth1 (3G dongle).

Everything was fine and it is here that a problem showed up, I wanted to go back to Ethernet once it is back, but I had noway of doing so while my 3G connection was running (issuing ping 8.8.8.8 -I eth0 wasn t working even thought I brought up eth0) I had to take down eth1 so I could check if the internet connection is back on eth0. I've realized that when I have both interfaces up only one is active at a time and I can't ping the internet through both using ping 8.8.8.8 -I eth0' and 'ping 8.8.8.8 -I eth1 at the same time. my question is :

Is it possible to ping through the two interfaces while both up?

If yes then How?

2
  • Could you add the output of route -n to your question, when eth0 and eth1 are up separately, and when they're both up? Jul 19, 2016 at 15:20
  • @John WH Smith Thanks for being interested but i already found the solution ,I made sure to share it with the community .voila
    – Ezwig
    Jul 19, 2016 at 16:48

1 Answer 1

1

Apparently the problem is that by default, you can only have one default gateway on a system. The case described would lead to asynchronous routing.

Solution

The iproute2 program, which is included in all current Linux distributions and already installed even, as a rule, can be used for the solution of this problem. Normally, a Linux system only has one routing table, in which only one default gateway can make entries. With iproute2, you have the ability to setup an additional routing table, for one thing, and allow this table to be used by the system based on rules, for another. Initial Position

We will assume that we have two interfaces: eth0 and eth1. The two networks that should be used are 192.168.0.0/24 and 10.10.0.0/24, whereby the first IP address in each respective network should be the gateway. The initial configuration would appear as follows. /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface

auto lo
iface lo inet loopback

# The primary network interface

allow-hotplug eth0
iface eth0 inet static
    address 192.168.0.10
    netmask 255.255.255.0
    gateway 192.168.0.1

# The secondary network interface
allow-hotplug eth1
iface eth1 inet static
    address 10.10.0.10
    netmask 255.255.255.0

Adding a Second Routing Table

To add a new routing table, the file, /etc/iproute2/rt_tables must be edited. We will call the routing table “rt2” and set its preference to 1. The named file should then appear as follows.

#
# reserved values
#
255     local
254     main
253     default
0       unspec
#
# local
#
#1      inr.ruhep
1 rt2

Configuring the New Routing Table

From this point, four commands are needed to achieve our goal. First, the new routing table needs to be populated, which is done using the following command.

ip route add 10.10.0.0/24 dev eth1 src 10.10.0.10 table rt2
ip route add default via 10.10.0.1 dev eth1 table rt2

The first command says that the network, 10.10.0.0/24, can be reached through the eth1 interface. The second command sets the default gateway. Routing Rules

So that the system knows when to use our new routing table, two rules must be configured.

ip rule add from 10.10.0.10/32 table rt2
ip rule add to 10.10.0.10/32 table rt2

These rules say that both traffic from the IP address, 10.10.0.10, as well as traffic directed to or through this IP address, should use the rt2 routing table.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .