Cannot connect ubuntu server 22.04 to internet on a RaspberryPi 3B+ using a 4G USB modem and netplan

I am trying to connect ubuntu server 22.04 to internet on a RaspberryPi 3B+ using a 4G USB modem and netplan.

The USB dongle seems to be recognized:

carlo@pi-box:~$ lsusb
Bus 001 Device 008: ID 19d2:0016 ZTE WCDMA Technologies MSM ZTE Mobile Broadband

carlo@pi-box:~$ sudo dmesg | grep usb
[  423.387073] usb 1-1.3: new high-speed USB device number 10 using dwc2
[  423.497368] usb 1-1.3: New USB device found, idVendor=19d2, idProduct=0016, bcdDevice=54.24
[  423.497428] usb 1-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[  423.497452] usb 1-1.3: Product: ZTE Mobile Broadband
[  423.497474] usb 1-1.3: Manufacturer: ZTE,Incorporated
[  423.500645] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB0
[  423.502143] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB1
[  423.503982] usb 1-1.3: GSM modem (1-port) converter now attached to ttyUSB2

The netplan configuration is:

network:
    renderer: NetworkManager
    ethernets:
        eth0:
            dhcp4: true
            optional: true
        usb0:
            dhcp4: true
            optional: true
    modems:
      ttyUSB2:
        apn: mobile.vodafone.it
        dhcp4: true
        auto-config: true
    version: 2

With the ifconfig -a command I find no interface.

The modem-manager seems to recognize the modem:

carlo@pi-box:~$ mmcli -L
    /org/freedesktop/ModemManager1/Modem/1 [ZTE CORPORATION] MF833V

carlo@pi-box:~$ mmcli -m 1
  --------------------------------
  General  |                 path: /org/freedesktop/ModemManager1/Modem/1
           |            device id: c22dd449a679d1e0ad941d57c707e8fbabaf3ee4
  --------------------------------
  Hardware |         manufacturer: ZTE CORPORATION
           |                model: MF833V
           |    firmware revision: BD_CNGENMF833VV1.0.0B08
           |            supported: gsm-umts, lte
           |              current: gsm-umts, lte
           |         equipment id: 860493042386496
  --------------------------------
  System   |               device: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3
           |              drivers: option
           |               plugin: zte
           |         primary port: ttyUSB2
           |                ports: ttyUSB0 (qcdm), ttyUSB1 (at), ttyUSB2 (at)
  --------------------------------
  Status   |       unlock retries: sim-pin (3), sim-puk (10)
           |                state: registered
           |          power state: on
           |          access tech: umts
           |       signal quality: 41% (recent)
  --------------------------------
  Modes    |            supported: allowed: 2g; preferred: none
           |                       allowed: 3g; preferred: none
           |                       allowed: 4g; preferred: none
           |                       allowed: 2g, 3g, 4g; preferred: none
           |              current: allowed: any; preferred: none
  --------------------------------
  IP       |            supported: ipv4, ipv6, ipv4v6
  --------------------------------
  3GPP     |                 imei: 860493042386496
           |          operator id: 22288
           |        operator name: 0046003 0046003
           |         registration: home
           | packet service state: attached
  --------------------------------
  3GPP EPS | ue mode of operation: csps-1
  --------------------------------
  SIM      |     primary sim path: /org/freedesktop/ModemManager1/SIM/1

The network-manager shows the device and the connection:

carlo@pi-box:~$ nmcli

ttyUSB2: disconnected
        "ZTE Mobile Broadband"
        1 connection available
        gsm (option), hw

carlo@pi-box:~$ nmcli c

NAME                      UUID                                  TYPE      DEVICE
netplan-ttyUSB2           5b6fbb52-0291-359e-aa68-b49f69ba9ff2  gsm       --

If I force the connection of the modem it seems successful:

carlo@pi-box:~$ sudo mmcli -m 1 --simple-connect="apn=apn.fastweb.it"
successfully connected the modem

carlo@pi-box:~$ mmcli -m 1
  --------------------------------
  General  |                 path: /org/freedesktop/ModemManager1/Modem/1
           |            device id: c22dd449a679d1e0ad941d57c707e8fbabaf3ee4
  --------------------------------
  Hardware |         manufacturer: ZTE CORPORATION
           |                model: MF833V
           |    firmware revision: BD_CNGENMF833VV1.0.0B08
           |            supported: gsm-umts, lte
           |              current: gsm-umts, lte
           |         equipment id: 860493042386496
  --------------------------------
  System   |               device: /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3
           |              drivers: option
           |               plugin: zte
           |         primary port: ttyUSB2
           |                ports: ttyUSB0 (qcdm), ttyUSB1 (at), ttyUSB2 (at)
  --------------------------------
  Status   |       unlock retries: sim-pin (3), sim-puk (10)
           |                state: connected
           |          power state: on
           |          access tech: umts
           |       signal quality: 38% (recent)
  --------------------------------
  Modes    |            supported: allowed: 2g; preferred: none
           |                       allowed: 3g; preferred: none
           |                       allowed: 4g; preferred: none
           |                       allowed: 2g, 3g, 4g; preferred: none
           |              current: allowed: any; preferred: none
  --------------------------------
  IP       |            supported: ipv4, ipv6, ipv4v6
  --------------------------------
  3GPP     |                 imei: 860493042386496
           |          operator id: 22288
           |        operator name: 0046003 0046003
           |         registration: home
           | packet service state: attached
  --------------------------------
  3GPP EPS | ue mode of operation: csps-1
  --------------------------------
  SIM      |     primary sim path: /org/freedesktop/ModemManager1/SIM/1
  --------------------------------
  Bearer   |                paths: /org/freedesktop/ModemManager1/Bearer/0
carlo@pi-box:~$ mmcli -b 0
  ---------------------------------
  General            |        path: /org/freedesktop/ModemManager1/Bearer/0
                     |        type: default
  ---------------------------------
  Status             |   connected: yes
                     |   suspended: no
                     | multiplexed: no
                     |   interface: ttyUSB2
                     |  ip timeout: 20
                     |  profile id: 2
  ---------------------------------
  Properties         |         apn: apn.fastweb.it
                     |     roaming: allowed
  ---------------------------------
  IPv4 configuration |      method: ppp
                     |      prefix: 0
  ---------------------------------
  Statistics         |  start date: 2024-03-05T21:26:00Z
                     |    attempts: 1

But with the ifconfig -a command I still could not find any related interface.

If I try to connect it signal an error on the APN:

carlo@pi-box:~$ sudo nmcli c up netplan-ttyUSB2
Error: Connection activation failed: Failed to select the specified APN
Hint: use 'journalctl -xe NM_CONNECTION=5b6fbb52-0291-359e-aa68-b49f69ba9ff2 + NM_DEVICE=ttyUSB2' to get more details.

The connection properties are:

carlo@pi-box:~$ sudo nmcli c show netplan-ttyUSB2
connection.id:                          netplan-ttyUSB2
connection.uuid:                        5b6fbb52-0291-359e-aa68-b49f69ba9ff2
connection.stable-id:                   --
connection.type:                        gsm
connection.interface-name:              ttyUSB2
connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)
connection.multi-connect:               0 (default)
connection.auth-retries:                -1
connection.timestamp:                   0
connection.read-only:                   no
connection.permissions:                 --
connection.zone:                        --
connection.master:                      --
connection.slave-type:                  --
connection.autoconnect-slaves:          -1 (default)
connection.secondaries:                 --
connection.gateway-ping-timeout:        0
connection.metered:                     unknown
connection.lldp:                        default
connection.mdns:                        -1 (default)
connection.llmnr:                       -1 (default)
connection.dns-over-tls:                -1 (default)
connection.wait-device-timeout:         -1
ipv4.method:                            auto
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       --
ipv4.dns-priority:                      0
ipv4.addresses:                         --
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.routing-rules:                     --
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-iaid:                         --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.dhcp-hostname-flags:               0x0 (none)
ipv4.never-default:                     no
ipv4.may-fail:                          yes
ipv4.required-timeout:                  -1 (default)
ipv4.dad-timeout:                       -1 (default)
ipv4.dhcp-vendor-class-identifier:      --
ipv4.dhcp-reject-servers:               --
ipv6.method:                            ignore
ipv6.dns:                               --
ipv6.dns-search:                        --
ipv6.dns-options:                       --
ipv6.dns-priority:                      0
ipv6.addresses:                         --
ipv6.gateway:                           --
ipv6.routes:                            --
ipv6.route-metric:                      -1
ipv6.route-table:                       0 (unspec)
ipv6.routing-rules:                     --
ipv6.ignore-auto-routes:                no
ipv6.ignore-auto-dns:                   no
ipv6.never-default:                     no
ipv6.may-fail:                          yes
ipv6.required-timeout:                  -1 (default)
ipv6.ip6-privacy:                       -1 (unknown)
ipv6.addr-gen-mode:                     eui64
ipv6.ra-timeout:                        0 (default)
ipv6.dhcp-duid:                         --
ipv6.dhcp-iaid:                         --
ipv6.dhcp-timeout:                      0 (default)
ipv6.dhcp-send-hostname:                yes
ipv6.dhcp-hostname:                     --
ipv6.dhcp-hostname-flags:               0x0 (none)
ipv6.token:                             --
gsm.auto-config:                        yes
gsm.number:                             --
gsm.username:                           --
gsm.password:                           <hidden>
gsm.password-flags:                     0 (none)
gsm.apn:                                --
gsm.network-id:                         --
gsm.pin:                                <hidden>
gsm.pin-flags:                          0 (none)
gsm.home-only:                          no
gsm.device-id:                          --
gsm.sim-id:                             --
gsm.sim-operator-id:                    --
gsm.mtu:                                auto
proxy.method:                           none
proxy.browser-only:                     no
proxy.pac-url:                          --
proxy.pac-script:                       --

What am I doing wrong? Does anyone have experience on this setup?

Asked By: carlo1601

||

I found out where was the issue.
I share my experience, maybe it could be helful to someone else.
I solved the APN issue by forcing the APN also on the connection (to specify it only in the netplan yaml file was not enough):

nmcli c modify netplan-ttyUSB2 gsm.apn mobile.vodafone.it

and I force the auto-config to false in the netplan yaml file.
After that, when I try to connect I obtained a different error:

PPP service disconnected

I tested the same use case with a ubuntu server 22.04 installation on a standard amd64 PC and everything worked as expected.
On the PC when I connect (sudo nmcli c up netplan-ttyUSB2) a ppp0 interface is created, with a IP address.
After looking around I found that on the raspberrypi some linux modules are missing, so I installed them:

sudo apt install linux-modules-extra-raspi

After that everything worked smoothly like on the PC.

Answered By: carlo1601