To identify the GSM carrier of an inserted SIM card into a Linux host:
mmcli -m 0|grep "operator name"|cut -d ':' -f2|xargs
With this information the APN for the GSM connection can now be set correctly.
It seems that NetworkManager automatically reuses an existing connection. In case your existing connection does not have any secrets stored, the new connection attempt will not update the existing connection and fail due to missing secrets. So in my case these steps helped:
nmcli con delete <SSID>
Then reconnect using
nmcli dev wifi connect <SSID&...
The problem was solved by updating and installing the realtek firmware. The following is the command :
apt-get update && apt-get install firmware-realtek
The solution was found in this post Debian jessie 8.5 doesn't detect wireless
turning it off with:
nmcli networking off
then back on again with:
nmcli networking on
nmcli connection reload
nmcli con down eth0
nmcli con up eth0
Or you can use nmtui
nmtui is a text based user interface for controlling network manager, when we execute nmtui, it will open a text base user interface through which we can add, modify and ...
You should change that either in the frontend of your choice or with nmcli:
nmcli con mod name ipv4.addresses ip
(substitute name with the connection name and ip with the desired ip address.
For more documentation visit: https://wiki.archlinux.org/index.php/NetworkManager
An adaptation of @TomHale-s answer to just get the active connection status:
CONNECTION_UUID=$(nmcli -t -m multiline -f UUID connection show --active | head -n1 | cut -c 6- )
METERED=$(nmcli -t -m multiline -f connection.metered connection show "$CONNECTION_UUID" | cut -c 20-)
# possible values are "yes", "no", "unknown":