With NetworkManager, how do I set the currently connected connection on my device (say wlp2s0) as metered?

How do I unset it in such a way that guessing of the metered/unmetered state will still occur?

Note: some hotspots will be metered (eg my phone) and some won't (eg home), so setting this on the device isn't what I'm after.


I really hope that this isn't the best answer: it seems convoluted in the simple case, and even more so if allowing for a binary SSID. Anyways, here goes:

Get device's current connection

nmcli -t -f GENERAL.CONNECTION --mode tabular device show $DEVICE | head -n1

-t is required as there is a space appended at the end otherwise (!?).

Show current metered status

nmcli -f connection.metered connection show $CONNECTION

Where $CONNECTION is the string returned by the previous command.

Change metered status

The valid statuses are yes, no, and unknown. unknown is the default, which will do the guessing based on things like DHCP option ANDROID_METERED (reference).

Example: set $CONNECTION to be metered:

nmcli connection modify $CONNECTION connection.metered yes

Allowing for binary SSIDs

To do this "right" (allowing for 32 arbitrary octets in the SSID), you'll need to use the device's GENERAL.CON-PATH:

nmcli -t -f GENERAL.CON-PATH --mode tabular device show DEVICE | tail -n1

This will return a string like: /org/freedesktop/NetworkManager/ActiveConnection/39

Then use this path to get connection's GENERAL.CON-PATH. NB: this has a different value (a device's CON-PATH == connection's GENERAL.DBUS-PATH)

nmcli -t -f GENERAL.CON-PATH -m tabular connection show apath /org/freedesktop/NetworkManager/ActiveConnection/39

This will return a string like: /org/freedesktop/NetworkManager/Settings/5 (note no ActiveConnection). This can be then used to modify the connection:

nmcli connection modify /org/freedesktop/NetworkManager/Settings/<NUMBER> connection.metered <VALUE>
  • Shouldn't that be head, not tail, in the first snippet? – Luciano Jun 9 '17 at 21:27
  • @Luciano, no because the device is listed on the first line. – Tom Hale Jun 10 '17 at 5:15

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":
echo "$METERED"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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