Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I start a VPN connection (it's already all configured) from a shell on OSX? I have looked through the man entry on net but I don't think that's it. launchctl might be more promising...

Edit: I've made the title more general because I think the question would apply to any kind of network connection.

share|improve this question
up vote 2 down vote accepted

See this thread. Basically you can Applescript it. Here's a full example:

osascript <<END 
tell application "System Events"
   tell current location of network preferences
       set VPNservice to service "Your VPN Name"
       if exists VPNservice then connect VPNservice
   end tell
end tell

You can even make another script replacing the word "connect" for "disconnect."

share|improve this answer

You can toggle network connections' state by using networksetup -setnetworkserviceenabled NameOfService on/off, e.g.

networksetup -setnetworkserviceenabled "AirPort" off

to disable the AirPort connection.

Enabling VPN connections this way doesn't connect them (AFAICT) though.

share|improve this answer
Yes, -setairportpower is more specific to AirPort, but it's just an example. -setnetworkserviceenabled is more general. Also, they perform different actions: A disabled AirPort network connection cannot be powered on. – Daniel Beck Apr 2 '11 at 23:35
Thanks @Daniel Beck, I put in an answer myself, after a bit of thinking horizontally about it ;) – Dan Rosenstark Apr 3 '11 at 6:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .