January 17, 2016

Automatic VPN on Android with Tasker and OpenVPN

Disclaimer: I imported this post from WordPress to Jekyll on 9/2/23. Forgive the misformatting until I get a chance to clean it up.

In the Barrett house, our wireless router is running DD-WRT with the OpenVPN client to a 3rd-party VPN provider always enabled. To hinder tracking by ISPs and the NSA, I try always to connect to a VPN on Android. When I enable it while connected to my home network, however, I notice a performance hit because I am recursively tunneling through a tunnel already being created by our wireless router. Using Tasker (root is not required) in conjunction with OpenVPN Connect, I have automated the connection and disconnection of the VPN service on my Android device. However, I do not take the extra performance overhead of the second connection when I am at home. Here is how you can automatically connect to VPN on Android using this same strategy.

Assumptions

You must have a subscription to an OpenVPN-compatible service. You should configure OpenVPN Connect on your Android phone per the instructions provided by your VPN service. You must also purchase and install Tasker before continuing.

I am not sure why, but it seems that Tasker must also have the Location Android permission enabled for the profiles to be triggered correctly.

Tasker Tasks

Configure the following two tasks with one action each in Tasker. 1Note: Items in curly brackets {} should be treated as variables and replaced.

“VPN Connect” Task

Add action type “System”->“Send Intent” and configure as follows.

“VPN Disconnect” Task

Add action type “System”->“Send Intent” and configure as follows.

Tasker Profiles

Configure the following two profiles in Tasker and link them to the task specified.

“Wi-Fi Disconnected” State Profile

Add profile and set as follows. Link this profile to the “VPN Connect” task.

“Wi-Fi Connected” State Profile

Add profile and configure as follows. Link this profile to the “VPN Disconnect” task.

via levgen