Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a system without X display and I want to use nmcli to configure my cell modem to connect to a certain apn. I can get it going with this modem just fine on Ubuntu (with X) and I would like to achieve the same now on the command line. How can I setup the connection?

so far I get this:

# nmcli dev status

** (process:2379): WARNING **: Could not initialize NMClient /org/freedesktop/NetworkManager: Permissions request failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.PolicyKit1 was not provided by any .service files
DEVICE     TYPE              STATE        
ttyUSB1    gsm               disconnected 
eth0       802-3-ethernet    connected 
share|improve this question
up vote 1 down vote accepted

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.

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 or wholesale.

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.

share|improve this answer

Assuming you have a more recent version than 0.9.6:

$ nmcli --version
nmcli tool, version 0.9.8.8-2.fc19

You can create devices like so via the command line using the dev commands within nmcli:

excerpt from nmcli man page

   nmcli dev wifi con "Cafe Hotspot 1" password caffeine name "My cafe"

          creates a new connection named "My cafe" and then connects it to 
          "Cafe Hotspot 1" SSID using "caffeine" password. This is mainly 
          useful when connecting to "Cafe Hotspot 1" for the first time. 
          Next time, it is better to use 'nmcli con up id "My cafe"' so that 
          the existing connection profile can be used and no additional is 
          created.

However creating connections is still a very new feature for nmcli, and isn't even listed in my F19's version of NetworkManager (0.9.8.8). Looking into F20 and RHEL7 Beta I noticed these examples which would seem to indicate that the option might be coming soon, 2.4. Using the NetworkManager Command Line Tool, nmcli.

$ nmcli connection modify id 'MyCafe' 802-11-wireless.mtu 1350

So perhaps if your distro has a newer version of NetworkManager you could add it like that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.