We want to use AirVPN's SSL tunneling mode on Android. SSL tunneling can be very useful, especially to defeat firewalls that block OpenVPN or SSH on a protocol level. We will use the Termux Terminal Emulator to install and run stunnel and OpenVPN for Android to manage the OpenVPN connection.
- Android 6.0 or newer (5.0 and derivatives thereof such as FireOS should work too)
- the Android device does not have to be rooted
- Google PlayStore or the free & open source F-Droid market (recommended)
- OpenVPN for Android (FOSS) – or Air's official Eddie Android Edition Please stay tuned for future Eddie releases as they may include native SSL tunnel support (which would make this cumbersome guide unnecessary)
- Termux Terminal Emulator (FOSS)
- stunnel (FOSS), via Termux repository
- a separate computer to download/edit the config files (entirely optional, but recommended)
Part 1: generate AirVPN config files
1/7: open AirVPN's config generator. When asked for your operating system, pick Linux:
2/7: Choose servers: Pick a single server. Do not select more than one. Do not select a whole region.
3/7: Protocols: First, enable Advanced Mode:
Now select the SSL mode, port 443:
4/7: Accept Terms of Service and generate the config files:
5/7: Download the generated zip archive:
6/7: unzip AirVPN.zip and open the *.ssl file in a text editor.
find this line:
pid = /tmp/stunnel4.pid
replace it with:
pid = /data/data/com.termux/files/home/stunnel4.pid
7/7: Now transfer the AirVPN folder to your phone's sdcard / main storage directory. For ease of use, don't put it into any subdirectories. Instead, put it into your "root" storage directory, meaning on the same level as your other default Android folders such as Documents, Download and Movies.
Part 2: Install and prepare Android software
1/3: Install OpenVPN for Android, via F-Droid or Play Store. Don't configure anything just yet.
2/3: Install Termux Terminal Emulator, via F-Droid or PlayStore
- open Termux and run:
- Allow Termux to access files on your device. (Android 8.0 Oreo users, please read the note at the end of this tutorial).
- The pkg command is used to install und update software packages. Make sure your base packages are all up to date:
- now install stunnel:
pkg install stunnel
3/3: Still in Termux, jump to the AirVPN folder you copied to your phone:
should list 3 files:
- AirVPN*.ovpn (the OpenVPN config file)
- AirVPN*.ssl (the stunnel config file)
- stunnel.crt (stunnel certificate)
Now start stunnel:
- press the Home button to get out of Termux.
- Start OpenVPN and import the AirVPN*.ovpn config file
- Edit your new OpenVPN connection (tap the "pencil button")
- in the ALLOWED APPS tab, tick the box next to Termux
- return to OpenVPN's connection list
- your VPN connection is now configured. A tap on its name will establish the connection.
- verify that a connection has been established by looking for the log entry Initialization Sequence Completed
- browse to ipleak.net (or any similar site) to verify that your traffic is indeed routed through the VPN tunnel
Here's a short video, demonstrating the steps above: https://vimeo.com/246306477
Part 3: Usage instructions
Now that everything is configured, future usage will be much easier:
- open Termux
- navigate to your AirVPN folder:
- now run stunnel:
- Press the Home button and open the OpenVPN app
- Connect to your VPN profile
- as an alternative to OpenVPN for Android, you can also use Air's official Eddie Android edition. Don't forget to dive into Eddie's settings to exclude ("blacklist") Termux from the VPN tunnel.
- don't forget to periodically run
pkg upgradeto keep all of Termux' packages, including stunnel, up-to-date.
- To prevent leaks, it's recommended to let OpenVPN set the default route for both IPv4 and IPv6; as well disabling the LAN bypass:
- you may want to take a look at Termux:Widget (via F-Droid or Play Store. It's an extension to Termux. If you put your stunnel commands into shell scripts, stored in ~/.shortcuts/ , you can launch them via Home screen widgets.
- enable Termux' extended keyboard by sliding out the left-side menu and long-pressing the KEYBOARD button. This will enable a row of additional keys, such as CTRL, ALT and TAB which are very useful in a terminal environment -- especially the TAB key, allowing you to autocomplete command and path names. Here's a short video on Vimeo demonstrating the extended keyboard.
- you may generate config files for as many servers as you like, put them into your AirVPN folder on your phone and add the *.ovpn profiles to OpenVPN.
- you may want to consider AFWall+ for additional firewalling (root required)
- it is recommended to move the *.ssl and stunnel.crt files out of Android's shared storage and into Termux' private data directory, while also deleting the no longer needed *.ovpn file:
cd ~ mkdir st cd storage/shared/AirVPN cp *.ssl stunnel.crt ~/st rm *.ssl stunnel.crt *.ovpnMoving those files obviously changes the paths of your Termux commands. Instead of running:
cd storage/shared/AirVPN stunnel AirVPN*.sslYou'd now need to run:
cd ~/st stunnel AirVPN*.ssl
- Following this tutorial will add the Termux app to OpenVPN's exclusion list, allowing it connect to the VPN server. But this also means that anything else you may do via Termux will also bypass the VPN tunnel. If you need a VPN-tunneled terminal app, I recommend using Termux only to run stunnel; using another terminal emulator app for your other tasks.
Addendum: Testing and bugs
This tutorial has been tested on:
- Stock Android 6.0
- Stock Android 7.0
- Stock Android 8.0
- LineageOS 14.1 (~ Android 7.1.x)
- Fire OS 184.108.40.206 (~ Android 5.x), testing done by user steve74it
Important Notice for Android 8.0+ (Oreo) users:
The command termux-setup-storage does not work (yet). Instead, follow this workaround to access storage:
The workaround will no longer be necessary once this bug is resolved:
- Thu Dec 7 20:24 UTC 2017: initial release
- Thu Dec 7 20:40 UTC 2017: formatting corrections
- Thu Dec 7 20:58 UTC 2017: spelling
- Fri Dec 8 18:47 UTC 2017: add recommended route settings. credit and thanks to Darkspace-Harbinger
- Fri Jan 5 17:30 UTC 2018: add note that this guide is functional on FireOS 5.6 (Android 5.x). testing done by user steve74it, thank you!
- Mon Jan 22 18:34 UTC 2018: add mikevvl's security tip to move files out of shared storage. thank you!
- Sun Jul 15 12:16 UTC 2018: recommend against alternative VPN apps (thanks steve74it)
- Tue Jul 17 12:20 UTC 2018: mention Eddie compatibility (thanks steve74it)
Any corrections, further testing, as well as general suggestions for improvement would be much appreciated.