Internet kill switch for Ivacy VPN on Mac: I have tested it on macOs Sierra. It might work on other versions of mac. Use at your own risk. Use this as a guideline for setting up your own kill switch. You need to change few things to get it working for yourself. With minor changes it should work for other VPNs also.
Files:
- kill-switch : this is the shell script providing status/start/stop/restart functionalities.
- Variables
- CONN_NAME : Name of your vpn connetion in
Sytem Preferences > Network
. For me it is Ivacy.
- CONN_NAME : Name of your vpn connetion in
- ks.conf: It is the
pfctl
config template. - Variables
- VPN_PROVIDER_ADDR : I figured out the address
for reconnecting Ivacy using
tcpflow -c -i en0
. From the captured packets you can zero in on all the ip-addresses required to connect. - WIFI, VPN : Corresponding Interfaces
- VPN_PROVIDER_ADDR : I figured out the address
for reconnecting Ivacy using
Usage:
- Turn off kill-switch
- Enable auto reconnect in your vpn dialer
- Connect to desired location/server
- Turn on kill-switch
- When vpn connection drops, It allows connections to vpn provider only. Hence auto reconnect works fine.
- After vpn reconnection every thing works fine
- Turn off the kill switch if you want to connect regularly.
Note:
sudo iftop -i en0
is an useful command to check what traffic is going out from wifi without vpn. You should see a vpn destination addr transferring a lot of data. This address is whitelisted by kill-switch during start up.