0

I have a Raspberry Pi (OS: Raspbian, debian based), that is connected to a router via Ethernet and a GSM module via USB.

I have a situation where I need to switch internet access between two interfaces based on availability.

If the Ethernet (eth0) does not have internet connectivity (but still connected to LAN), the GSM module (ppp0) needs to be used. If the internet connectivity is available on eth0, then eth0 should be used.

pi@raspberrypi:~ $ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         0.0.0.0         0.0.0.0         U     0      0        0 ppp0
default         192.168.3.1     0.0.0.0         UG    202    0        0 eth0
10.64.64.64     0.0.0.0         255.255.255.255 UH    0      0        0 ppp0
192.168.3.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0

I want to know, is there any way if I can configure the routing in such a way that is is handled.

If not, then what command should I fire to switch different interface as primary (do I have to change metric?)

Dushyant Bangal
  • 123
  • 1
  • 1
  • 9
  • You need to explain the need to switch internet access based on availability. Kevin's answer contains a script that pings 8.8.8.8 and if fails changes the default route. – cusco Jul 20 '18 at 17:52

2 Answers2

0

Show your routes by ip route instead of route : it is deprecated (like netstat and ifconfig).

You can change the metric with the ip route change 0.0.0.0/0 dev ppp0 metric 100.

But I don't know how you can automate this.

Dom
  • 6,743
  • 1
  • 20
  • 24
0

You are looking for a route failover which can be performed by running this dual WAN failover script from Apsu found on Gist.

Kevin K.
  • 383
  • 1
  • 7