Is there a better way to get my network interface switching between eth0 and ppp0?


#1

I’ve gotten all my network interfaces working but it’s really screwy how I’ve had to switch between them and am wondering if there’s a better way?

I have got a cellular modem connected to my Beaglebone Green and am using the resin/beaglebone-green-node image. If ethernet is physically plugged in on startup then my only interface in my container is eth0 and I have connectivity. When I run pon to turn on my cell modem I do see the ppp0 interface come up in ifconfig. However, running route I see that the default route is still eth0. Further, I now actually have no Internet connectivity – I can’t even ping google. My workaround has been to create a startup script for my CMD in the Dockerfile, that turns off ethernet, waits 5 seconds then runs poff:

# disable ethernet because it conflicts with fona ppp0 interface
echo "unmounting ethernet (eth0) interface"
ifconfig eth0 down

# wait a few seconds for ethernet to go down or else starting fona will conflict
echo "waiting 5s..."
sleep 5s

# enable 3g module
echo "mounting 3g (ppp) interface"
pon fona

This works in that it does create the default ppp0 route which now works but then I can’t get back to using ethernet without restarting the BB and changing to a container that doesn’t run my startup script. Would love to learn if there’s a better way. Could it be related to this issue in any way?


#4

Hi. Can you give us more details on how you set up the ppp configuration? Do you run pppd in the container with a custom cunfiguration?


#5

Sure! I do what they do in this tutorial, in the container:

Except I can’t get the network interfaces file which automatically configures ppp0 to work on boot so I run

pon fona

In my startup.sh which runs based on me specifying it in the Dockerfile in CMD

Thanks!

Cheers,

Andrew


#8

Hi, the above article seems to provide instructions on how to connect to the internet through a cellular data connection. Is this what you essentially want to do? If yes, you will need to set up GPRS to wifi sharing. So you will need to define a cellular NetworkManager file to connect. Then you can create a hotspot using this: https://docs.resin.io/deployment/network/2.x/#creating-a-hotspot and define the sharing interface as the ppp0 instead of the eth0.


#10

Creating a cellular data connection isn’t exactly what I’m asking about – I followed the Adafruit instructions and they worked – I was able to get a data connection. My question is mostly about how it appears to conflict with the eth0 interface (I have a beaglebone green which is ethernet, not wifi). I have a workaround where I have to force eth0 to go down before I can bring ppp0 up.

Your link about creating a hotspot – if I were to pursue that approach, would that replace the Adafruit instructions to acheive the same goal of establishing the ppp data connection? Would that solve my original problem of conflicting with eth0? Lastly, would I really use ‘wifi sharing’ if I don’t have wifi? I want to understand what this does and how it solves my issue before I spend a lot of time trying it out.

Thanks!


#11

Hey @abcd,
So let me try understand what you are looking to setup. You basically want to set up a Beaglebone green to use the fona modem via UART to give you a GSM network connection. You also want this connection to be the primary route to the internet rather than the ethernet port. Will the ethernet port be connected to another network?

ResinOS has a service called ModemManager installed in it and at boot this service will try to discover and configure any modems attached to it, whether they are USB or UART, so the first test would be to connect up the fona modem to your BBG and the boot a dev version resinOS on it. You can then either SSH or use serial console into the device and run the following commands to check if the modem is being discovered correctly:

List all discovered modems:

mmcli -L

Get the logs from ModemManager

journalctl -u ModemManager --no-pager

If the modem is being correctly setup, the first command above will show you which modem number it is and then you can see the modem details using mmcli -m 0 where 0 is the modem number it shows you previously.

if you system is correctly showing a modem, then the next step is to set up a connection file to correctly point it to the APN, etc. For this you need to create a file on the BBGs file system in /mnt/boot/system-connections the file should look something like the one listed here: https://docs.resin.io/deployment/network/2.x/#cellular-modem-setup , but replacing the APN with your cellular providers APN.

After this you can reboot the BBG and when it comes up, you can check if the new cellular connection is correctly brought up by using the following command: nmcli -c no c you should see a new connection there with a type of GSM and connected to a ppp0 interface.

Now to make your cellular interface the primary route to the internet you just need to add the following file to your /mnt/boot/system-connections folder:

[connection]
id=my-ethernet
type=ethernet
interface-name=eth0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=

[ipv4]
never-default=true
route-metric=2000
dns-search=

ignore-auto-routes=true
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto

This connection profile will be assigned to the eth0 interface and will set it to have a lower route-metric than the cellular connection, so all network traffic will automatically be routed through cellular rather than ethernet.

Some notes on the above:

  • You should try use as new a version of resinOS as possible as they have latest NetworkManager and ModemManager, for the BBG I suggest using the Beaglebone Black v2.7.8 image (don’t worry, the Beaglebone Black images now work on all Beaglebone device types, green, green wifi and Blue)
  • Running and setting up modem connections from within the container is not encouraged or supported by resin, this is because it becomes very easy to remotely brick or mess up the connectivity during container updates and we have seen it happen too often. The recommended approach is to always us NetworkManager and ModemManager.

Let me know if this is what you are looking for or if I have misunderstood anything.