How can I configure Mac OS X such that it can only allow an internet connection (both downloads and uploads) through a given VPN connection?

If the VPN connection disconnects, the internet should stop working.

I need to do this due to security reasons. Sometimes I use ISPs that I have no reason to trust. Especially on wifi hotspots.

How do I do this? I'm sure there is nothing I can do through the Mac OS X GUI, but is there any hack I can do via the Terminal?

migrated from stackoverflow.com Aug 9 '11 at 6:48

This question came from our site for professional and enthusiast programmers.


If you are making a VPN connection, isn't the default route for all traffic to use that connection?

Anyway, set a default route to the VPN. Traffic should stop when the link dies.

It's late and I might not be interpreting your question clearly :D

  • That's all well and fine while the VPN connection is active. However, if the VPN connection prematurely disconnects (and while I'm away from my computer and thus don't notice it), the internet connection will fall back to my insecure default non-VPN connection. That's what I want to avoid. – Enchilada Aug 13 '11 at 13:37

I doubt this is possible with the VPN stuff in OS X. Correct me if I'm wrong.

However, I was able to solve this by using OpenVPN and Tunnelblick.app. Tunnelblick has capabilities for running scripts when the VPN connection dies. So I just run a script that turns off the Ethernet/AirPort when the VPN dies. Seems to be working.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.