nmcli - Disconnect VPN Without Specifying ID or UUID

Bug #1338382 reported by Lonnie Lee Best
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
NetworkManager
Fix Released
Medium
NetworkManager-OpenVPN
New
Undecided
Unassigned
network-manager-vpnc (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

In a recent attempt to eliminate steps when switching between VPNs ( https://bugs.launchpad.net/ubuntu/+source/network-manager-vpnc/+bug/1215262 ), I discovered a need for adding an additional option to the nmcli command.

Currently, in order to disconnect a VPN, you have to specify its id or uuid. I'm proposing that a general disconnection feature be added that will disconnect any connected VPN without having to specify its id or UUID.

This need becomes more clear when you attempt to automate switching between VPNs, as I describe in this comment:
https://bugs.launchpad.net/ubuntu/+source/network-manager-vpnc/+bug/1215262/comments/4

As you can see, without this proposed feature, switching between VPNs is very verbose to automate.

I wish there was a command like this:
nmcli con down allvpn

This proposed command would disconnects any currently connected VPNs (without the necessity of specifying their id or uuid).

Tags: trusty utopic
Revision history for this message
Lonnie Lee Best (launchpad-startport) wrote :

If you are connected to a VPN, this command will return a list of established VPN connections:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$'

This command will list the IDs of any established vpn connections (one per line):
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP '^.*?(?=\s{2,})'

So to disconnect all VPN connections you could do it based on this ID like this:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP '^.*?(?=\s{2,})' | sed 's/^/\x27/' | sed 's/$/\x27/' | xargs -L1 nmcli con down id

However, perhaps it is better to do this using the UUIDs.

You can list the UUIDs of all established VPN connections like this:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP '(?<=[\s]{2})[^\s]+(?=(\s+[^\s]+){2}\s+yes.*)'

So you can disconnect all established VPN connections by UUID like this:
nmcli con status | grep -oP '^(([^\s]+\s){1,}[\s]{2,}){4}yes.+$' | grep -oP '(?<=[\s]{2})[^\s]+(?=(\s+[^\s]+){2}\s+yes.*)' | xargs -L1 nmcli con down uuid

Perhaps this logic could be added to nmcli, so that this following proposed option would concisely achieve the same results:
nmcli con down allvpn

Changed in network-manager:
importance: Undecided → Unknown
status: New → Unknown
Changed in network-manager:
importance: Unknown → Medium
status: Unknown → New
Revision history for this message
Lonnie Lee Best (launchpad-startport) wrote :
Changed in network-manager:
status: New → Fix Released
Revision history for this message
Lonnie Lee Best (launchpad-startport) wrote :

In the new version of nmcli (version 0.9.10.0), you can disconnect all VPN connections with the following command:

nmcli connection show --active | grep vpn | grep -oP .{8}-.{4}-.{4}-.{4}-.{12} | xargs -L1 nmcli con down uuid

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in network-manager-vpnc (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.