Skip to content

Instantly share code, notes, and snippets.

@h4k1m0u
Last active December 7, 2025 22:45
Show Gist options
  • Select an option

  • Save h4k1m0u/d20d6f6b79704569534fc6f70e02208b to your computer and use it in GitHub Desktop.

Select an option

Save h4k1m0u/d20d6f6b79704569534fc6f70e02208b to your computer and use it in GitHub Desktop.
Configure a 4G USB dongle on linux

Notions

  • /dev/cdc-wdm1: Linux device node for a Qualcomm-based 4G/5G modem. Used to send commands to modem (See QMI).
  • wwan0: Network interface on Linux for a cellular modem that uses 4G/5G.

Configuration

$ # Connect the dongle with the pin code already disabled
$ mmcli -L  # List the connected modems. modem-code: number at the end
$ mmcli -m <modem-code>  # Show state of modem
$ mmcli -m <modem-code> --create-bearer='apn=orange,user=orange,password=orange'  # Create bearer (connection session). bearer-code: number at the end
$ mmcli -m <modem-code> -b <bearer-code> --connect  # Connect to given bearer
$ mmcli -m <modem-code>  # Look for "state: connected (in green)"
$ sudo udhcpc -i wwan0 -f -qn  # Request an ip address
$ ip address  # Check that the interface wwan0 has been assigned an IPv6 address

Troubleshooting

$ sudo systemctl status ModemManager.service  # Shows the last logs from mmcli
$ sudo systemctl status NetworkManager  # Shows the last logs from the network manager (incl. network interfaces like wwan0)

Note

KDE

Go to System Settings > Network > Connections, and create a new mobile broadband connection.

#!/usr/bin/env bash
set -ex
modem_code=$(mmcli -L | awk '{ print $1 }' | awk -F "/" '{ print $NF }')
mmcli -m "$modem_code" --simple-connect='user=orange,password=orange,apn=orange' # automatically creates a bearer, then connect
# Add following at end of `visudo` to avoid asking for password
# hakim ALL=NOPASSWD: /usr/sbin/udhcpc
sudo udhcpc -qn -f -i wwan0
#!/usr/bin/env bash
set -ex
modem_code=$(mmcli -L | awk '{ print $1 }' | awk -F "/" '{ print $NF }')
mmcli -m "$modem_code" --simple-disconnect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment