Connect to VPN from macOS Command Line

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:

FIXME

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:

greys@maverick:~ $ 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:

greys@maverick:~ $ networksetup -showpppoestatus "HomeVPN"
connecting

and then – eventually – confirm it’s connected:

greys@maverick:~ $ networksetup -showpppoestatus "HomeVPN"
connected

See Also




Keep Learning

Follow me on Facebook, Twitter or Telegram:
Recommended
I learn with Educative: Educative
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets