Network interface bonding under ResinOS 2.0

Hey guys,

Does anyone already have experience with network bonding under ResinOS 2.0?

Some of my devices are on sketchy internet connections, so there I would like to install a 3g-modem (usb dongle) as a BACKUP. Now I noticed that ResinOS 2.0 does this almost perfectly, because if I have both LAN and 3g enabled, the LAN connection has higher priority in the routing table and will therefore get all the traffic.
Also when the LAN is unplugged, the 3g connection takes over without a problem.

But in many of the RealLife cases the LAN connection is not actually unplugged, but it is the MODEM (behind the router) that is giving trouble. The LAN keeps being connected to the router still has a gateway address. Therefore the RasPi will still give priority to the LAN connection, resulting in an unreachable RasPi.

I think this might be solved by bonding the LAN & 3g connections. Any experience with this?

All help greatly appreciated.

Gr, Frans

@FransvanHoogstraten, in general anything you can do with network manager should be possible in resinOS.

I had a quick google and it is supported so I suggest grabbing a dev image and giving it a try - I thought that this link looked the most promising, under the “Configuring bonded interface” section.

Ok, good to hear that it should be possible.

In the blogpost they configure NetworkManager with the “nmcli” command. I can’t imagine I am able to control the ResinOS NetworkManager from within my container right? I think I should do it via configuration files in the /system-connections folder on the SD?

yeah or via dbus from the user container, there are a couple of libraries I have used previously that allow you to do that:

Thanks Joe!

hey @FransvanHoogstraten

Did you manage to get this working?

Hi @joe not yet!

Struggling with busy agenda, so for now I am just switching devices with sketchy wired (LAN) connection over to 3g-modem without bonding.

It is still high on my prio list tho, so will def pick it up!

Cool, I am attempting this myself at the moment so I will make sure to let you know once I get it working.

Cheers!

Did any of you succeed with this?
I was planning to play around with bonding but I get operation not supported as soon as I attempt to enable a bonded connection.

hi @mhe_lorenz no I didn’t.

I have another solution for this which has been working flawlessly on all my device. I have a script that

  • continuously monitors all network interfaces: whether they can ping 8.8.8.8 and wat their latency is.
  • if the current default gateway loses its internet connection or latency becomes too high, I switch to the gateway of the other internet interface (if available). Switching is done via dbus.

@mhe_lorenz, @FransvanHoogstraten

We enabled related functionality in balenaOS v2.34.0 - the NetworkManager connectivity section.
For reference: https://github.com/balena-os/meta-balena#connectivity

The way this works is by having an external URL that a device regularly checks from all available interfaces. By default it is an URL on our API servers. If the URL cannot be reached then the route metric for the tested interface is given less priority by NetworkManager. Thus if a LAN connection is up, but the Internet cannot be reached through it, a secondary connection like cellular or WiFi will end up having a better route metric and Internet will be accessed through it.

Other methods could be employed as well of course, since we are running the standard Linux networking stack and all is accessible for configuration from the application containers.

Please let me know if you have any questions.

Thanks,
Zahari

@FransvanHoogstraten thanks for the quick response. I was considering doing something similar had @majorz not responded what he did above.

@majorz that seems like great standard functionality to handle failover from one interface to another. However, without hijacking this thread, what I actually want to do is to increase the throughput by e.g. balancing two gsm interfaces in a bonded interface. Also, if one degrades or completely fails the other should be used as failover.

I never tried doing that before but it should definitely be possible. You may do some tests using nmcli from the host OS, and then implement it through one of the libraries available for NetworkManager from application container (or by invoking nmcli through it). Here is one of the top examples that show after search: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-network_bonding_using_the_networkmanager_command_line_tool_nmcli

For reference, I now doubt this is possible. Network manager bonding does not seem to support gsm.

@FransvanHoogstraten what tool did you use to change the default gateway?

I’d like to combine your solution with monitoring of rssi and thus the built in solution is not ideal.

I looked it up, but it wasn’t via dbus. This is my code to switch to a different gateway:

def assign_default_network_adapter(self, new_network_adapter, new_gateway):
    self.logger.info("Now switching to new_network_adapter: " + new_network_adapter + " at gateway: " + new_gateway)
    command = "ip route replace default via " + new_gateway  # add new default route
    self.logger.info("Executing command:" + command)
    os.system(command)

Where new_network_adapter is the name/description of the network adapter
And new_gateway is the IP of the new gateway