# Virtual private networks

## On browsing the internet confidentially

You don’t want ISPs and governments to annotate the data they already have on you with a list of which sites you visit and when? VPNs, Tor, SSH tunnels can keep what you are doing on the internet quiet, by allowing you to access the internet virtually from somewhere else; Ideally a somewhere else crowded with other people with whom you can be confused.

The EFF tells Americans it is time to get a VPN. This applies also in my jurisdiction, Australia. Probably it is time everywhere, except places like China where may be too late.

VPNs do of course degrade the bandwidth of your internet, but Australians are used to awful internet anyway, so this is not a major issue.

OK, you need a VPN to maintain privacy. Which one? How? Serverwise, do you want to DIY, or pay someone else to provide it? Which VPN software should you use?

(Or should we bypass the internet with a sneakernet or DIY internet? That’s another story.)

There are related technologies here that do very similar things. OpenVPN, IPSec, Wireguard… The fashionable new one is Wireguard but AFAICT it is not widely supported yet, and there are questions about how anonymous it is in commercial VPN provider environments. In the interim, pretty much all the consumer VPNs seem to use OpenVPN.

## Client-end

Now you want to install the right client software; this is usually fairly straightforward. Just get an account with some VPN provider, and follow their instructions. Two I see mentioned often are Blackvpn and NordVPN. (Disclaimer: I get a cut if you sign up using that latter link.) See below for more on that choice.

This works great for my phone or laptop in some arbitrary cafe hotspot, but it is not ideal for my home devices on the home intranet. See below for VPN access points.

Having set up the VPN there are still data leakages per default. Vpn.ac has a nice basic list of basic privacy steps disabling unsafe behaviour from the web browser end etc, and one should still enable the usual browser safety steps.

### Linux

So you followed the recommended setup for your VPN provider. Good.

Gotcha: OpenVPN is broken for DNS on Linux by default, in the sense that switching to a VPN connection keeps the same old DNS servers that you were using before. In the absence of further effort, OpenVPN on Linux will use your ISP’s DNS, informing them which site you want and will believe their potentially lying responses. This seems to defeat the purpose.

I think this is not a pure Linux problem per se but because VPN providers tend to provide wrapper scripts for macOS and Windows, one only notices this monstrous oversight on Linux where you one is going bareback. Not 100% sure on that, don’t care quite enough to find out.

Lazy detection of this problem is possible via DNSLeaktest who report

As of OpenVPN version 2.3.9 you can now prevent DNS leaks by specifying a new OpenVPN option. Simply open the.conf (or .ovpn) file for the server that you are connecting to and add the following on a new line.

block-outside-dns

For OpenVPN before 2.3.9 there is a laborious workaround that no normal person will realistically ever use to automatically change DNS.

One can always use the DNS config to override the DNS to never use your ISP’s DNS, which you probably should do. On GNOME/Ubuntu using a large VPN provider with hundreds of servers the default way of doing this will be messy and require hundreds of custom DNS configurations which is no fun at all. 🏗 workaround.

Another problem is that VPN occasionally disconnects and then you are not protected and you don’t notice.

Auto-reconnect is not available in e.g. modern GNOME desktops, but you can access this setting using the command:

nm-connection-editor

To make sure your computer does not leak information during a vpn disconnect, perhaps vpnfailsafe would be a good idea, or other iptables-based hardening.

## VPN access points

Per default, our household devices should not have to route communications between one another via Amsterdam. This is terrible for sharing files from the network files server or copying photos, or streaming from the household media server etc. Instead, our network should be a normal wifi network, but the wire that connects us to the outside world, everything that goes over that wire should be encrypted.

To do that, one sets up a VPN router/access point. If you are taking one of the VPN options, an understanding of basic firewall management is advisable.

### DIY VPN router

Tedious. You need a fancy router, and the crappy free one you got from your ISP isn’t fancy. Basic routers typically have about 64MB RAM and unbelievably feeble CPUs. They are computers that would have seemed under-powered in the year 2000 that for some reason we pay a giant premium to have wired into the broadband, and if you try to do something even mildly taxing, such as securing their communications, they fall over and die. I suppose there is a good antenna on these things, but also the debugging/upgrading experience is bad. So you need to buy a fancy router and upgrade it. This requires more time and research and money than you would ideally like. For now, here’s a link to a setup guide from a major commercial provider.

### Pre-rolled VPN router

Gradually becoming more affordable although still expensive because decent modern routers are still remarkably expensive. If you trust the vendors, this might be a viable option. Techradar reviews some options. Flashrouters reconfigures third party routers (affiliate link); Their surcharge is small; It is hard to imagine beating their total price unless you value your labour at nothing or work as a network tech and flash routers all day or something.

### Make a computer into a VPN access point

Any linux machine with wifi can be a wireless access point—even, or especially, a crappy old spare laptop too slow for anything else. This is typicall cheaper than buying fancy router and even a crappy laptop is faster than most routers, although with worse antennae. If you want to understand what you are doing here without doing a whole IT degree, the smoothest theoretical intro I have found is Carla Schroder’s Linux Networking cookbook, (although it is no longer a practical intro because it came out more than a decade ago) and there are various explanations on the theory of netfilter. Also Jim Salter’s rant that routers are terrible computers for the price, in the form of a HOWTO, is kinda interesting. You can even do this all with a GUI on recent ubuntu. It seems that a minimally decent computer with a good antenna would be a better value proposition and also easier for idiots like me who want to plug in a keyboard or such. Nitty-gritty-I-don’t-care-why-tell-me-how intros? See this grumpy but simple and acclaimed stackoverflow answer. There are some wrinkles.

### Single-board-computer VPN access points

One can do this especially economically using a single board computer such as the Raspberry Pi, which even out-of-the-box has respectable wireless performance. This seems like a good idea when you first think of it. My, you think, that will use very little power and require little space and I can keep the computer half-way up a wall somewhere and that will be fine. In practice it has been much more difficult for me since the reason that the computer is so tiny and efficient is that it has no screen or keyboard, and inevitably something breaks down in the network stack and I need a screen and keyboard attached to diagnose it and they are both really hard to attach to a tiny computer half way up the wall. Many hours have I lost in diagnosing a problem, thinking it was fixed forever and then the moment I put the raspberry pi somewhere inconvenient, everything falls apart. Pro tip: if you are doing this is a raspberry pi 4, do not use a case unless it has a fan, or the device will overheat and crash. Basic WAP (Wireless access point) setup is supported by the rasppi folks themselves. Here is their recommended setup that worked fine for me as a vanilla (non-VPN) AP. I did run into problems with the iptables-restore not running after a VPN reconnect. Mustafa Çalap’s setup is even simpler but seems to handle VPN disconnection with even less grace. The Zentralwerkstatt howto uses a slightly different software profile (adding in isc-dhcp-server and iptables-persistent) than the others, which means you can avoid some of the manual iptables configuration but I’m less familiar with what is going on. I will try this next in the hope it is more reliable. AFAICS the necessary bits of the classic dovyez universal firewall are

#hostAP stuff
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i eth0 -o wlan0 -m state \
--state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

# HostAP requires the lines below to both be ACCEPT to function
iptables -A INPUT -j ACCEPT >> /dev/null 2>&1
iptables -A OUTPUT -j ACCEPT >> /dev/null 2>&1

The ZadenRB one includes a hand-rolled web interface, which looks convenient but also flakey. 🤷‍♂ I ignored the bits about web interfaces with this howto. I had the problem that the dnsmasq configuration would never update after openvpn launched on restart, which seemed to be about setup of the /etc/dnsmasq.conf being fragile when things booted up in the wrong order. Also it made lots of rules to enable VPN access TO the pi externally, which is not an extra attack surface I need right now.

So far, even though it looks very long, the two part pimylifeup write-up seems to have worked best. It’s only long because it overexplains; there are not in fact many steps and the setup seems fairly robust.

For any of these, one should also secure the pi.

Bonus tip: the wifi might crash for issues related to the brcmfmac driver. Possibly a firmware updates helps. I have experienced this bug on the Raspberry pi 3B+ but it is not clear to me how widespread it is, and I have not reproduced in on recent raspbian builds.

To make sure your intranet does not leak information during a vpn disconnect, perhaps vpnfailsafe would be a good idea.

In practice, even the simplest options are stupidly complex for something that should be a ubiquitous default. Realistically, what I do is usually: try to configure an access point, then discover that there is some weird kernel error/bug specific to the particular device I am using, which has never been seen on the internet, which requires a specialist network nerd, and which I don’t have time to fix. The latest version of the pi and its OS work fine, mind you, but this kind of challenge is very much typical of trying to cobble together security for non-spooks.

I am somewhere in the topmost single-digit percentiles of the population in terms of fluency in stupid geeky shit like this and it is at best marginally feasible for me to work this stuff out and set it up. Realistically most of my friends who have a worse ROI on time spent doing this are not using VPNs and therefore too much data is being leaked to unaccountable surveillance programs. The world is awful.

## Server end

That which provides your devices this service of confidentiality.

Note, that server virtual machines on someone else’s cloud can never be especially secure from determined nasty persons or state actors. But they do at least prevent concerted profiling by commercial interests, and casual ambient profiling by the state, which is good enough for me.

A commercial VPN provider can do better, if their intentions are pure, sicn ethey can hide your traffic amongst the traffic of many others. On the other hand, a commercial VPN might be selling your data to evil bastards for their own profit, so… make your own risk assessment.

Two I see mentioned often are Blackvpn and NordVPN (Disclaimer: I get a cut if you sign up using that latter link.).

### Commercial VPN services

That one privacy guy’s big overview lists VPN providers by e.g. bandwidth, jurisdiction, and privacy advocacy.

#### Nordvpn

Seem fast and cheap. Their record with disclosing security breaches could be better.

Server configs may be downloaded en masse, as a zip or individually. They have client software. I think it is supposed to sidestep the DNS leak problem amongst other things. It does not for me.

sudo apt install {/path/to/}nordvpn-release_1.0.0_all.deb
sudo apt install nordvpn
mkdir -p ~/.config/nordvpn

You also need to enable some services:

sudo systemctl enable --now nordvpnsd
systemctl --user enable --now nordvpnud

There are quirks in this software.

Firstly it is so insanely aggressive in enforcing VPN that it redirects localhost. You have to whitelist localhost ports individually, using

nordvpn whitelist 12345

(UPDATE: seems to be fixed now.)

The second quirk is that it is closed-source software, and therefore inscrutable.

### DIY OpenVPN server

Running your own VPN/proxy/anonymizing/p2p etc servers can be less convenient for the panopticon in its ceaseless attempts to get up in your business, if you do not trust the VPN providers (but, if it is hosted in a cloud, you do trust the cloud providers.) The tradeoff here is that you want to share a VPN server with other people so that you are collectively anonymized. If it is just me always using the same VPN server then it is not very hard to de-anonymise me; I’m the guy who is always using that server. Once again, make your own risk assessment here.

Even easier than real VPN, try turning your SSH login into a quasi-VPN via sshuttle.

sshuttle --dns -r username@sshserver 0/0

## Stealth mode

Hiding that you are hiding. obfsproxy and other tor pluggable transports attempt this. It is not so simple and if we really want normal people to go through these tedious steps people will die of boredom before they ever get around to overthrowing their repressive regimes.

You can get pre-rolled scripts from help sites such as scramblevpn which tells you how to make a cheap Raspberry Pi router.

## Tor

Is already its own proxy/privacy thingy. If you are using a computer on Tor you should not use a VPN through Tor. If you want to hide that you are using Tor you could use Tor through a VPN.

## Other

How does tcpcrypt fit in?

tcpcrypt is a protocol that attempts to encrypt (almost) all of your network traffic. Unlike other security mechanisms, Tcpcrypt works out of the box: it requires no configuration, no changes to applications, and your network connections will continue to work even if the remote end does not support Tcpcrypt, in which case connections will gracefully fall back to standard clear-text TCP. Install Tcpcrypt and you’ll feel no difference in your every day user experience, but yet your traffic will be more secure and you’ll have made life much harder for hackers.