Network failover

The NetworkManager support in Digi Embedded Yocto includes network failover. This means that when the primary network interface loses the connection, NetworkManager replaces the current network interface with the next-available network interface that has connectivity. This happens without user intervention.

Note See the NetworkManager documentation for more detailed information about NetworkManager options.

The network failover works at two different levels:

Note Upstream connectivity check functionality is not enabled by default. See Enable upstream connectivity check.

To establish the priorities between the different network interfaces, see Set interface priorities and metrics.

Detect loss of physical link

NetworkManager brings a network interface down when it detects the loss of its physical link.

For example, a system with Ethernet, Wi-Fi, and cellular interfaces using DHCP has a routing table similar to the following:

#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.101  0.0.0.0         UG    100    0        0 eth0
0.0.0.0         192.168.11.101  0.0.0.0         UG    600    0        0 wlan0
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0

If the physical Ethernet link is lost, NetworkManager brings the interface down and removes its entries from the routing table:

#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.101  0.0.0.0         UG    600    0        0 wlan0
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0

This allows the system to reach the Internet over the interfaces that have connectivity.

Check upstream connectivity

NetworkManager allows you to perform a connectivity check by sending an HTTP request to a given URI and waiting for the specified response. 

When enabled, NetworkManager performs upstream connectivity checks over each interface in the routing table. When the check fails for one interface, NetworkManager penalizes the metric of that interface in the routing table so it is no longer the default that the system uses to reach the Internet.

NetworkManager continues to perform connectivity checks over all the interfaces. As soon as the connectivity is restored over a previously failing interface, the metric is also restored to the original value and the routing table goes back to the original state.

Note This support not enabled by default. To enable, see Enable upstream connectivity check.

Enable upstream connectivity check

  1. Open the NetworkManager configuration file located at /etc/NetworkManager/NetworkManager.conf:
  2. Edit the configuration file and add the connectivity section:
    This section controls NetworkManager's optional connectivity checking functionality. This allows NetworkManager to detect whether the system can actually access the Internet or whether it is behind a captive portal.
/etc/NetworkManager/NetworkManager.conf 
[connectivity]
uri=http://network-test.debian.org/nm
interval=...
response=...
  • uri: The URI of a web page to periodically request when connectivity is being checked. This page should return the header X-NetworkManager-Status with a value of online, or its body content should be set to NetworkManager is online. Use the response  option to control the body content check. If this option is blank or missing, connectivity checking is disabled.

Some examples of web pages with NetworkManager responses:

URI

Response

http://network-test.debian.org/nm

NetworkManager is online

https://fedoraproject.org/static/hotspot.txt

OK

http://nmcheck.gnome.org/check_network_status.txt

NetworkManager is online

https://www.pkgbuild.com/check_network_status.txt

NetworkManager is online

  • interval (in seconds): Controls how often connectivity is checked when a network connection exists. If set to 0, connectivity checking is disabled. If missing, the default is 300 seconds.

Note The minimum value for the interval option is 60 seconds. If you set a lower time, the connectivity check may not work.

  • response: Controls what body content NetworkManager checks for when requesting the URI for connectivity checking. If missing, defaults to "NetworkManager is online".
  1. Save the changes in your file.

CAUTION! Issue the sync command after editing the /etc/NetworkManager/NetworkManager.conf file.

  1. To apply all your changes, restart NetworkManager.
#> /etc/init.d/networkmanager restart

Note For information on how to include your NetworkManager.conf in your Digi Embedded Yocto images, see Set NetworkManager configuration.

For example, for the same configuration shown above with Ethernet, Wi-Fi, and cellular:

#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.101  0.0.0.0         UG    100    0        0 eth0
0.0.0.0         192.168.11.101  0.0.0.0         UG    600    0        0 wlan0
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0

If at any time the connectivity check fails over the Ethernet interface, NetworkManager changes the metrics so the new routing table looks like this:

#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.101  0.0.0.0         UG    600    0        0 wlan0
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
0.0.0.0         192.168.11.101  0.0.0.0         UG    20100  0        0 eth0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0

Note how the Ethernet interface has been penalized and the new primary interface is Wi-Fi.

If, later, the Wi-Fi interface also loses connectivity to the configured URI, the routing table would change:

#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
0.0.0.0         192.168.11.101  0.0.0.0         UG    20100  0        0 eth0
0.0.0.0         192.168.11.101  0.0.0.0         UG    20600  0        0 wlan0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0

Note that the cellular interface is now the default.

Set interface priorities and metrics

The priority of the network interfaces is specified by their metric: the lower the metric, the higher the priority. By default, NetworkManager uses default metric values for each interface type where Ethernet has the highest priority (lowest metric) and cellular the lowest (highest metric).

#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.101  0.0.0.0         UG    100    0        0 eth0
0.0.0.0         192.168.11.101  0.0.0.0         UG    600    0        0 wlan0
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0

To set the metric of any interface:

  1. Configure the new value:
[connection]
id=wlan0
type=wifi
interface-name=wlan0
 
[wifi]
ssid=""
 
[ipv4]
method=auto
route-metric=50
 
[ipv6]
method=ignore
#> nmcli con modify wlan0 ipv4.route-metric 50
  1. Bring the connection down and then back up for the changes to take effect. For example:
#> nmcli con down wlan0
#> nmcli con up wlan0
  1. To verify the changes have been applied, use the route command to print the routing table:
#> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.11.101  0.0.0.0         UG    50     0        0 wlan0
0.0.0.0         192.168.11.101  0.0.0.0         UG    100    0        0 eth0
0.0.0.0         77.210.151.17   0.0.0.0         UG    700    0        0 ppp0
77.210.151.17   0.0.0.0         255.255.255.255 UH    700    0        0 ppp0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 wlan0
192.168.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     100    0        0 eth0
192.168.0.0     0.0.0.0         255.255.0.0     U     600    0        0 wlan0