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.
NetworkManager: Set current connection of device as metered
networkmanager;nmcli
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 connectionnmcli -t -f GENERAL.CONNECTION --mode tabular device show $DEVICE | tail -n1-t is required as there is a space appended at the end otherwise (!?).Show current metered statusnmcli -f connection.metered connection show $CONNECTIONWhere $CONNECTION is the string returned by the previous command.Change metered statusThe 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 yesAllowing for binary SSIDsTo 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 -n1This will return a string like: /org/freedesktop/NetworkManager/ActiveConnection/39Then 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/39This 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>