Package: network-fallback-service
AboutThis is a simple script to automatically switch between network interfaces on a Linux system when a remote host is unreachable, as tested with ping or curl.When the primary interface is not working, a secondary interface will be used. When the primary interface is working again, the system will automatically swap back to it. If none of the interfaces are working, the script will reboot the system after a given amount of retries.InstallationUse./install.shto install. It:Runspip3 install network-fallback-serviceto install the two executables in your path:network-fallback-launchandnetwork-fallback-configRuns the interactive config utilitynetwork-fallback-configto create a new config for your device. Also creates thesystemdservice file in/etc/systemd/system/network-fallback.serviceand reloads the systemd daemonUsageUse systemctl to start/stop the service:systemctl enable --now network-fallback.servicesystemctl disable --now network-fallback.serviceDefining interfacesTo ensure an interface is compatible with this service, it should be set up in ifupdown or NetworkManager, two of the common Linux network interface managers. Your config should be detailed enough that NetworkManager can enable the interface simply runningnmcli dev connect <interface>. Refer to the NetworkManager documentation for more information.Etherneteth0should work with no extra config (considering the IP settings are correct for your install site. Static IP / DHCP setting can be adjusted inai-config)WiFiwlan0will work given you have created a wireless network connection before. Seenmclidocumentation for adding to a wifi network. It will likely be like this:nmcli radio wifi onto make sure its onnmcli dev wifi listto see list of SSIDssudo nmcli dev wifi connect <SSID> password "<Passowrd>"Other InterfacesAll NetworkManager interfaces must be configured so that NetworkManager knows how to adjust the routing table properly when runningnmcli dev connect <interface>. Check the NetworkManager documentation for more information on setting up your specific use case.Manual ConfigThe config files are located in/etc/network-fallback.d, with the following format:[iface.NAME]
primary = true
type = ifupdown
persistent = true

[iface.NAME]
type = NetworkManager
gateway = 192.168.0.1
persistent = true

[check.ping]
type = ping
host = 8.8.8.8
makeRoute = true

[checks]
interval = 30
retryLimit = 6

[system]
debugLogs = true/false[iface.NAME]Supply the interface name in the section headerprimary, for if this is the primary interfacegateway, for if this interface accesses the internet via a gateway (ie a router)persistent, controls if the device should be disabled if it keeps failing (more than 5 times in a row)[checks.NAME]Name of the check can be anything uniquetype, may be ping or curl, this is how to test connection to the hosthost, is the ip address to test connection tomakeRoute, is if a temporary route to this host should be added to perform this connection check (useful for when the gateway must be defined to reach host on a given interface, ie an ethernet network with a router)[checks]interval, time in seconds between checks.retryLimit, how many failed checks in a row can be tolerated before rebooting.[system]debugLogsenables verbose output to stdout. Note stdout/stderr is captured by the systemd journal if running as a service.Viewing LogsAll logs can be viewed withjournalctl -u network-fallback, and the service status withsystemctl status network-fallback.service.