If you normally browse the web (and you don’t block ads), you’ve probably already seen hundreds, if not thousands, of advertisements for “VPNs” or “VPN software/subscriptions” — how you “need” one to have any kind of privacy, how “they”1 can track you everywhere if you don’t use one, and so on. And they’re usually not cheap. Interestingly, and probably because of some recent “revelations”, all those advertisements seem to focus on privacy or anonymity only.
But using a VPN can offer you something else: mobile security; namely, the ability to make your mobile devices “be”, on demand, part of your home network (or your server’s network, if you have, say, a VPS somewhere), no matter where you are, regardless of whether you’re using 3G/4G mobile data, or some random WiFi hotspot. Yes, even one with no encryption at all; it won’t matter. You can, absolutely, trust random open hotspots again; even their owner won’t be able to read or alter your traffic in any way. And you can do it for free, too (assuming you already have an always-connected Linux server); you just need to configure your own OpenVPN server, which you’ll be able to do by following this (hopefully accessible) guide.
Installing OpenVPN:
This tutorial will be Debian/Ubuntu-based, but it’s easy enough to adapt to other distributions (e.g. for a Red Hat-based Linux, just do “yum install” instead of “apt install“, and some defaults may be slightly different). Just enter:
Configuring OpenVPN:
(Note: this guide will focus on the goal mentioned in the second paragraph: configuring your “home” server (which doesn’t need to actually be at your home) to accept VPN connections from your mobile device(s), which will then make that/those device(s) act as if they were part of your “home” network. OpenVPN can do other stuff, but we won’t go into that here.)
(Note 2: if you’re using a server at home, you probably need to configure your modem/router to forward OpenVPN connections to your server. The default OpenVPN port is 1194 (UDP), but it can be changed (it’s specified in the configuration files below.))
First, copy some default configuration files:
Then edit the /etc/openvpn/easy-rsa/vars text file, and change the following variables from the defaults to something that makes sense for you. Most of these are “cosmetic”, so they don’t really matter, but it’s ugly to keep the defaults 🙂 :
Add another setting to that file:
(replacing “mysite.mydomain.com” with your server’s external name, of course.)
Then do:
The last command will ask for details for your private Certificate Authority (CA)’s certificate. Just answer with the same details you entered in the “vars” file above. In particular, “Common Name” must be your server’s public address.
Continuing:
Again, this will ask for certificate details. It’s OK to use the same you used for the CA. This will also confirm if you want to sign the certificate and commit the certification; answer “yes” both times.
Now enter:
Now, there are example server configuration files in /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz , but we’ll just create a simple one from scratch. Save the following as /etc/openvpn/server.conf :
Right now, you should be able to restart OpenVPN and have it running with no complaints. But, of course, this is just the server part; we still need to create a configuration file for each of your clients (which can be computers, tablets, mobile phones, etc.). In the following example, we’ll create one for an Android phone (though nothing here will be specific to Android).
On your server, do:
As before, it will ask for certificate details. Enter what you’d like, even in the “Common Name” field; here they’re all cosmetic.
Now create an .ovpn file for the new client. Put the following in an /etc/openvpn/android01.ovpn text file:
But this is not complete. For laziness’s sake (and, in my experience, required for iOS devices), we’ll also add the certificates (CA and client) and the client key here. Assuming they’re where the tutorial so far left them,
You also need a masquerading rule in your firewall. For instance (using the default OpenVPN network of 10.8.0.0/24):
Replace “eth0” with your public/outgoing network interface. And make it permanent, of course. If using ufw, just add:
to /etc/ufw/before.rules .
You must also have IP forwarding enabled. If your server acts as a firewall, it’s probably already on. You can check it with the command:
If it’s “1”, you’re fine. If not, you can do:
to enable it, and:
to make it permanent.
And that should be it. You now need to transfer this new .ovpn file (keep it safe, by the way, including from any other local users on your server!) to your Android (or other) device, and then open it in the OpenVPN client (which you need to install, of course — don’t worry, it’s free.) Each device has a specific way to import the .ovpn file, and the client typically helps you in doing so, so you’ll eventually succeed. 🙂 If everything goes well, you’ve just connected your phone (or some other device) to your own network, and everything between the two is fully encrypted. You may now want to play around with shortcuts so that you can “VPNize” your phone at the click of a button (say, when connecting to a public hotspot.)
As implied in this (now quite long) post’s introduction, this won’t do anything for your privacy; any site you access will see your home/server address, no matter where you are. So don’t use it to communicate with other insurgents, or hack government sites, or anything. 🙂 The point is simply to “make” even unknown hotspots as trustworthy as if you were home. (It may also help you get around some firewalls or traffic shaping, but you didn’t read that here. 🙂 )
Any comments/suggestions, please let me know in the comments.
Thanks to Reddit user ZeusHoldsMyJockstrap for reminding me about the missing IP forwarding part. 🙂 My home server has had IP forwarding enabled since 2007, so I totally forgot about it when writing this guide.
you should look into wireguard. openvpn is like 1990s 😉