I knew it's possible to setup VPN connections using native System Preferences in macOS, but discovered recently that it's possible to manage them from command line.
Today I'll just show you how to connect or disconnect from an existing VPN profile – perhaps some other time I'll explain how to setup VPN profile and connection parameters from scratch.
Reviewing Network Connections in System Preferences
You can find existing connections – networked, wireless, bluetooth and VPN – in Network section of the System Preferences app:
You can simply click the Connect button to activate VPN connection if you're already there in the settings screen. But using command line it's possible to activate the same VPN connection without ever opening System Preferences app or selecting the profile using keyboard and mouse.
Activate VPN Connection using networksetup
networksetup command lets you manage lots of network connection aspects.
Here's a command to activate VPN connection for my profile HomeVPN:
[email protected]:~ $ networksetup -connectpppoeservice "HomeVPN"
and although it's possible to review VPN connection status in System Preferences:
… it's also possible to check it from the command line:
[email protected]:~ $ networksetup -showpppoestatus "HomeVPN" connecting
and then – eventually – confirm it's connected:
[email protected]:~ $ networksetup -showpppoestatus "HomeVPN" connected