0

I'm using Raspberry Pi 3B. I've ethernet eth0 and a 4G module ppp0 connected. Priority connection is eth0. I can detect whether ethernet cable is connected to the raspberry pi or not using commands. But Can I check whether the internet is there or not without ping command?

I want such thing which can monitor all of my interfaces at the same time. If internet is available on eth0, the main interface will be eth0. When the internet is down on eth0, the connection should switch ppp0. As soon as the internet is available again on eth0, it should switch back to eth0.

How can I achieve this? I don't want to check this thing using ping command again and again after a fixed interval. Plz help.

theashwanisingla
  • 267
  • 1
  • 11
  • You have provided NO information about your setup, so if you do get answers these are likely to be speculative. It is possible that setting priorities may solve your REAL problem, rather than what you actually asked. – Milliways Nov 26 '19 at 08:49
  • Try installing ifplugd. That used to be in Raspbian and would switch to a WiFi network when the ethernet cable was disconnected. It's a right PITA and I'm glad it's gone in Buster. But, if it still works, it does what you want. – Dougie Nov 26 '19 at 08:56
  • Hi, priorities are absolutely right as per my needs. Ethernet is having the top priority. But I wanna know how to check for the internet on Ethernet when my 4G module is up. And I couldn't get what more information should I provide. I'm sorry. – theashwanisingla Nov 26 '19 at 08:57
  • Hi Dougie, my problem is a bit different. I don't want to know whether the cable is disconnected or not. I wanna know whether internet is working or not. – theashwanisingla Nov 26 '19 at 08:58
  • @Dougie About ifplugd: doesn't work with default dhcpcd but I have Make ifplugd available again since Raspbian Stretch. – Ingo Nov 26 '19 at 10:42

1 Answers1

2

What you want to have is a classical failover scenario. Fortunately Linux has a professional solution for it with bonding. With it you can combine two (or more) interfaces where you can configure what should be the primary interface and switch over to the reserved interface if the primary fails and switch back if the primary is available again. This all is done automatically without the need to monitor interfaces and switch them with scripts. How to do it with a Raspberry Pi you can look at Howto migrate from networking to systemd-networkd with dynamic failover.

Ingo
  • 42,107
  • 20
  • 85
  • 197