VPN Killswitch [Bash Script]

With the recent passing of the Cybersecurity Information Sharing Act (CISA) here in the US, concerns over privacy on the Internet have taken center stage again. As most readers probably know already, a VPN is a good way to help protect your privacy online (or is it?). VPN Killswitch is a simple bash script that increases protection by preventing your real IP address and Internet activities from being revealed in the event that you lose connection to your VPN.

How does VPN Killswitch work?

VPN Killswitch uses nmcli to make sure you’re still connected to a VPN. If you lose connection to your VPN, then VPN Killswitch issues an ifconfig down command on the ethernet adapter that you set, effectively terminating all access to the Internet (and preventing your information from being revealed).


1. Download the script

Download as a zip file: https://github.com/plasticbrain/vpnkillswitch/archive/master.zip

Or clone the github repository:

2. Set your internet device

Open vpnkillswitch.sh, find and edit the device variable. (If you’re not sure what to use, run ifconfig and use whichever device shows your external IP)

3. Move the script to /usr/bin (optional)

4. Make the script executable


Connect to your VPN, then open a terminal and run VPN Killswitch:

Note: VPN Killswitch needs to be ran as root so it can terminate your Internet connection

If you lose connection to your VPN then VPN Killswitch will run ifconfig down on the ethernet adapter that you defined in step 2 above.

Restore Internet Connection

To restore your Internet connection after it’s been stopped by VPN Killswitch just run the script with the up parameter:

2 responses to “VPN Killswitch [Bash Script]

  1. I’ve known about the kill switch functionality since quite a long time ago – some VPN providers offer it with their plans but not my provider. So I didn’t really give it a second thought. And today I just got a random idea – “Kill switch. Wait. On Linux, isn’t that just a shell script? *facepalm* Someone must have written that before.” Well, thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

×Mike Everhart

Need Some More Help? Let's Talk!

I'd love to work with you! Fill out the form below to schedule a free consultation to discuss your needs and how I can help.

Need More Help?