Raspberry Pi as VPN router (and wifi access point)
The problem with most vpn services is that the corresponding software needs to be installed on every device individually and might not even be available for a few devices (e.g. if you want to use a vpn service on your ps4). This is where a vpn router/wifi access point based on a raspberry pi can come into play. With this, you can just connect to the pi like you would to your regular router and all your traffic will be channeled through the vpn tunnel.
Prerequisites
- Raspberry Pi (3 preferably. Older versions work as well. In that case you need an additional wifi adapter though)
- A regular ethernet cable
Setting it up is pretty simple: Connect the raspberry to your regular router by using the ethernet cable. That’s it.
Setting up the access point
First, we will set up the access point. To do this we will assign the raspberry a static ip (here: 192.168.7.1). Edit the /ect/network/interfaces file:
Now, we will define the access point. First, install hostapd:
Edit the file /etc/hostapd/hostapd.conf and add your desired ssid and passphrase::
Lastly, we need to set up the dns service. Install dnsmasq
In this case ip adresses ranging from 192.168.7.5 to 192.168.7.254 can be assigned to connected devices. Edit /etc/dnsmasq.conf:
To finish setting up the accesss point just start the services:
Now try connecting to the access point and check if everything works as expected.
Setting up the VPN router
The next part is based on this tutorial on github.
First, set up the vpn on the raspberry. There are a lot of different VPN providers that provide support for the raspberry pi. I am using Cyberhost. You can find the tutorial for setting it up here.
After starting the vpn service we enable IP Forwarding
Route the traffic through the vpn
Save the changes
Select yes when you are asked if you want to save the current rules. You can also save the rules at a later stage:
Load the changes at startup
And this is it. Your vpn router/access point is now all set up.