VPN Wifi using Docker and CreateAp (Raspberry Pi)

Terms: 
1. Network gateway: local computer (ethernet layer) that routes outgoing packets.
2. VPN hotspot: wireless network with outgoing packets through a VPN.

Synopsis: The challenge was to create a VPN hotspot on the Raspberry Pi 3 without effecting the networking of the existing services. My solution was to create a network gateway inside a docker container and route the WiFi traffic to that gateway from the RPI host os.

In an ideal world it should of been easy, just open the tunnel interface with OpenVPN and route traffic from the wifi subnet through the vpn gateway route, however I am using a consumer VPN that doesn't have static routes (OpenVPN pulls new routing information with each connection). Leading to the obivous thought why not create a local network VPN gateway inside a container?  

This way if the VPN dies, the container won't route through the normal internet (due to iptables masquerade).

One dissapointment is that due to the Raspberry Pi 3 wifi drivers it isn't possible to pass control of the wifi adapter to the container in order to host the Wifi itself (the entirety of it could of been self contained)

Part 1: Creating the container

This will require you to use Windscribe and have your credentials easily accessible (You could easily change the script)

Dockerfile

Create directory vpngateway with the Dockerfile and type:

 docker build vpngateway -t chris:vpngateway
 

After that run it with:

 docker run -itd --name vpngateway --restart unless-stopped --privileged chris:vpngateway
 
Now you have a local network gateway that routes traffic through your vpn, use "Docker ps vpngateway" to get the containers ip. You can now test that your VPN network gatway is working by routing your favorite ip trackers through the gateway, 
 
 ip route add 46.101.9.128 via DOCKERIP
 
 

Part 2:  Routing only Wifi traffic through the local network gateway

Now we need to start the Wifi, you will need to download create_ap (make sure you have the dependencies dnsmasq and iptables).

Start create_ap

create_ap wlan0 eth0 vpnhotspot --no-dnsmasq
 
We have to hotspot setup but without any routing (packets not going anywhere).
 
Create routing table in /etc/iproute2/rt_tables
 
echo "10 vpn" >> /etc/iproute2/rt_tables
 
Forward packets from the Wifi subnet to go through the new VPN routing table 
 
/bin/ip rule add from 192.168.12.0/24 table vpn
 
Set the default route of the VPN table to the docker container ip:
 
/bin/ip route add default via 172.17.0.2 table vpn
 
Now everything from the Wifi hotspot will go through the VPN gateway inside the docker container! Complicated and not ideal, but it works!
 

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.