configure gsm connection using nmcli
A bit late to the party, but I was stuck at the same hurdle. Since I have worked it out I thought I'd share my findings as every other post on the topic is about as clear as mud.
Although NetworkManager can see the device, it doesn't know of any connections that are supported by the device. Unlike WiFi, we can't just do a scan to make a list of available connections. We need to add one ourselves.
Before creating the connection, ensure NetworkManager does not prevent the device from being managed. This is by default happening on Ubuntu Server to prevent NetworkManager from taking over an existing legitimate legacy connection (see explanation from Ubuntu developer here).
You can verify that the device is unmanaged whennmcli device
shows unmanaged
status for your device, the opposite being disconnected
. In this case, skip to the next paragraph.
To make NetworkManager on Ubuntu Server handle the connection, copy the file /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
to /etc/NetworkManager/conf.d/10-globally-managed-devices.conf
, then edit it: modify the line beginning with unmanaged-device
by adding gsm
type to the list of exceptions:
unmanaged-devices=*,except:type:wifi,except:type:wwan,except:type:gsm
Don't forget to check updates to the original /usr/lib file when upgrading NetworkManager.
Creating a connection
To start off with, we create a new connection named as you wish with the (appropriately named /s) edit
command e.g.:
sudo nmcli connection edit type gsm con-name "My GPRS Connection"
Use sudo
if you don't want to be disappointed when you try to save the connection.
Of course, if you aren't using GSM, you can change the type parameter to a different protocol supported by NetworkManager.
Now you will enter edit mode. Most of the settings you need are automatically filled in for you. You can see all the current settings with the print
command:
nmcli> print
===============================================================================
Connection profile details (My GPRS Connection)
===============================================================================
connection.id: My GPRS Connection
connection.uuid: 27b012ca-453f-482f-bc0e-c81bbab07310
connection.interface-name: --
connection.type: gsm
connection.autoconnect: yes
connection.timestamp: 0
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.secondaries:
connection.gateway-ping-timeout: 0
-------------------------------------------------------------------------------
ipv4.method: auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.routes:
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.never-default: no
ipv4.may-fail: yes
-------------------------------------------------------------------------------
ipv6.method: auto
ipv6.dns:
ipv6.dns-search:
ipv6.addresses:
ipv6.routes:
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.dhcp-hostname: --
-------------------------------------------------------------------------------
gsm.number: *99#
gsm.username: --
gsm.password: --
gsm.password-flags: 0 (none)
gsm.apn: --
gsm.network-id: --
gsm.network-type: -1
gsm.allowed-bands: 1 (any)
gsm.pin: --
gsm.pin-flags: 0 (none)
gsm.home-only: no
-------------------------------------------------------------------------------
Type help
to see a full list of commands.
The only thing you are likely to need to edit is the APN of your network. This can be set with set gsm.apn <APN>
where APN would be something like epc.t-mobile.com
, wholesale
or vzwinternet
for verizon.
You can also restrict the connection to a particular interface. This is not recommended especially for serial-based connections where the device name can change readily. If you wanted to though, you could do set connection.interface-name ttyS4
for example.
Provided you're running as root, you'll now be able to save your connection
nmcli> save
That's it. If you need to go back to edit the connection, use nmcli c edit "My GPRS Connection"
, or directly edit the config file. On Debian-based systems you'll find it in /etc/NetworkManager/system-connections/
, on Redhat it'll be in /etc/sysconfig/network-scripts/
. These files seem to be transferable from system to system - the UUID is basically random.
Connecting to our new connection
Now you should be able to connect with
sudo nmcli device connect <interface name>
If all goes well, NetworkManager will select "My GPRS Connection" automatically. If not,
sudo nmcli connection up "My GPRS Connection" ifname <interface name>
This is where it falls down for me right now. It times out during the connection but I think I'm out of signal range. Hopefully it works better for you.
Please comment if you need any more information.
It's a year later now and a lot of packages are updated. Using the ModemManager
service and mmcli
I was able to initialise my ublox SARA-U201
. ModemManager
already made the connection called "mymodem". The only thing that was not set right was the connection.interface-name
, so this one I had to clear. +1 for the accepted answer because it helped me in the right way to achieve this. To summarise, these are the commands that I had to run to get it up and running:
sudo mmcli -i 0 --pin=<pin_number>
sudo mmcli -m 0 --simple-connect="apn=my.carrier.apn"
sudo nmcli connection edit mymodem
nmcli>set connection.interface-name
Enter 'interface-name' value: (leave blank, press enter)
save
quit
sudo nmcli connection up mymode ifname ttyACM0
Note that these settings are saved except for the PIN of the SIM. If you require a PIN you have to using this command at every boot.