How to check that a VPN connection is connected or disconnected using command line?
4 Answers
If you want to know if any VPN-connection is active then the following invocation is useful:
nmcli con | grep -i vpnDepending of the connection status you will get either
VPN099 ... vpn wlan0if active or
VPN099 ... vpn ---if inactive.
This will show just the active connections:
nmcli con show --activeAnd you can grep for vpn, if needed:
nmcli con show --active | grep -i vpn 1 We can do this using nmcli command:
nmcli con status id your-vpn-connection-nameIf your VPN connection is connected, you will see the connection information but if your VPN connection is disconnected, you will see something like this:
Error: 'your-vpn-connection-name' is not an active connection. 3 The answer is great and 100% works for me
nmcli con show --active
But when I started use openconnect as Cisco Anyconnect alternative, instead of:
nmcli con show --active | grep -i vpn
I had to use next:
nmcli con show --active | grep -i tun