Fallback to working network interfaces
Project description
About
This 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.
Installation
Use ./install.sh
to install. It:
-
Runs
pip3 install network-fallback-service
to install the two executables in your path:network-fallback-launch
andnetwork-fallback-config
-
Runs the interactive config utility
network-fallback-config
to create a new config for your device. Also creates thesystemd
service file in/etc/systemd/system/network-fallback.service
and reloads the systemd daemon
Usage
Use systemctl to start/stop the service:
systemctl enable --now network-fallback.service
systemctl disable --now network-fallback.service
Defining interfaces
To 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 running nmcli dev connect <interface>
. Refer to the NetworkManager documentation for more information.
Ethernet
eth0
should work with no extra config (considering the IP settings are correct for your install site. Static IP / DHCP setting can be adjusted in ai-config
)
WiFi
wlan0
will work given you have created a wireless network connection before. See nmcli
documentation for adding to a wifi network. It will likely be like this:
-
nmcli radio wifi on
to make sure its on -
nmcli dev wifi list
to see list of SSIDs -
sudo nmcli dev wifi connect <SSID> password "<Passowrd>"
Other Interfaces
All NetworkManager interfaces must be configured so that NetworkManager knows how to adjust the routing table properly when running nmcli dev connect <interface>
. Check the NetworkManager documentation for more information on setting up your specific use case.
Manual Config
The 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 header
-
primary
, for if this is the primary interface -
gateway
, 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 unique
-
type
, may be ping or curl, this is how to test connection to the host -
host
, is the ip address to test connection to -
makeRoute
, 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]
debugLogs
enables verbose output to stdout. Note stdout/stderr is captured by the systemd journal if running as a service.
Viewing Logs
All logs can be viewed with journalctl -u network-fallback
, and the service status with systemctl status network-fallback.service
.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for network_fallback_service-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a3e97135d1597f2a3be9684b04945cbbde6791e5587f2bbf724dc623d506dc7 |
|
MD5 | e7145438095f0663be6c118b9edc067e |
|
BLAKE2b-256 | 12ac21ea8e8da65d34e0b2faa3186a391fe3a37bb1a448b29e0ced38600e34bf |
Hashes for network_fallback_service-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 287a0678488c71cb1a8511cebaed4d022dbc07a6c54d724b2b4d8b0c02ff2d31 |
|
MD5 | dc58e772940935cc4255ef8a96b6cc8c |
|
BLAKE2b-256 | f9becfde502730dacb6048bd57b9ab75b83fa547b8e52e963605be9fd5905d92 |