Start VPN connection from macOS Terminal

macOS comes with a VPN client by default, this is part of the network settings of the Mac. Via the settings you can add different VPN connections, by default there is support for IKEv2, Cisco IPSec and L2TP over IPSec.

Once the VPN connection is configured, you can start it from  ▸ System Preferences ▸ Network. You can also start a VPN connection from macOS Terminal. This allows you to start and/or stop a VPN from a script. You can also use this with commercial VPN services such as NordVPN, ClearVPN, etc.

Check VPN settings

To start or stop a VPN connection from Terminal, you need to find out the name of the VPN connection. Open  ▸ System Settings ▸ VPN.

Start VPN connection from macOS Terminal

On Macs running macOS Monterey or earlier, you can do this via  ▸ System Preferences ▸ Network in the left column you will see the configured connections. VPN connections are shown with a padlock, the name shown here is needed to be able to start and stop the VPN under Terminal.

Start VPN from Terminal

If you know the name of the VPN connection, you can use it to start the VPN connection from Terminal. To do this, use the command below, replacing “FritzBox” with the name of the VPN connection you want to start, don’t forget the quotation marks.

Copy
$ networksetup -connectpppoeservice "FritzBox"

After executing the command, the VPN connection will be started, you can check in  ▸ System Preferences ▸ Network if the connection is actually active. The command does not care which type of VPN connection is used. Only the name of the connection is necessary to be able to start it.

Stop VPN from Terminal

To stop the VPN connection in Terminal, replace -connectpppoeservice Through -disconnectpppoeservice in the command. After that, you fill in the name of the VPN connection. The command will then look like this.

Copy
$ networksetup -disconnectpppoeservice "FritzBox"

Once the command is executed, the VPN connection will be disabled. You can check in  ▸ System Preferences ▸ Network whether the connection is actually disconnected.

Check if a VPN connection is active

You can check whether a VPN connection is active via  ▸ System Preferences ▸ Network. This is also possible under macOS Terminal, for this you can use the command:

Copy
$ networksetup -showpppoestatus "FritzBox"

Replace “FritzBox” with the name of the VPN connection you want to check. After executing the command, you will see connected if this is connected or disconnected if the VPN connection is not active.

Quickly activate via Siri Shortcuts

Using the above Terminal commands, you can also create a Siri Shortcut so you can quickly start or stop your VPN connection via a Shell script. Open the Shortcuts app (from macOS Monterey) and create a new one. Search for ‘Run Shell Script’, add it to the command and fill in the custom command you find above. For ‘Shell’, choose ‘Bash’ and check the option ‘Run as administrator’. As soon as you start the command, the command will be executed.

Recent Articles

Related Stories