2018-09-21 16:39:08 +02:00
# Private Internet Access Client (OpenVPN+Iptables+DNS over TLS on Alpine Linux)
2018-02-06 21:57:41 -05:00
2018-09-21 16:39:08 +02:00
Docker VPN client to private internet access servers using [OpenVPN ](https://openvpn.net/ ), Iptables and Unbound (Cloudflare DNS over TLS) on Alpine Linux.
2018-04-15 14:15:58 -04:00
Optionally set the protocol (TCP, UDP) and the level of encryption using Docker environment variables.
2018-03-31 20:33:45 -04:00
2018-09-20 20:35:29 +02:00
A killswitch is implemented with the * iptables * firewall, only allowing traffic with PIA servers on needed ports / protocols.
2018-06-06 22:44:11 -04:00
2018-02-21 11:55:45 -05:00
[](https://hub.docker.com/r/qmcgaw/private-internet-access/)
2018-02-06 21:57:41 -05:00
2018-03-15 12:09:17 -04:00
[](https://travis-ci.org/qdm12/private-internet-access-docker)
2018-04-15 14:15:58 -04:00
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
[](https://github.com/qdm12/private-internet-access-docker/issues)
[](https://github.com/qdm12/private-internet-access-docker/issues)
[](https://github.com/qdm12/private-internet-access-docker/issues)
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
[](https://hub.docker.com/r/qmcgaw/private-internet-access)
2018-03-15 12:09:17 -04:00
2018-09-20 20:35:29 +02:00
[](https://microbadger.com/images/qmcgaw/private-internet-access)
[](https://microbadger.com/images/qmcgaw/private-internet-access)
2018-04-01 13:56:56 -04:00
2018-04-01 13:56:20 -04:00
| Download size | Image size | RAM usage | CPU usage |
| --- | --- | --- | --- |
2018-09-28 19:51:30 +02:00
| 6.6MB | 15.7MB | 14MB | Low |
2018-04-15 14:15:58 -04:00
2018-09-21 16:39:08 +02:00
## Features
2018-09-20 20:35:29 +02:00
2018-09-21 16:39:08 +02:00
- Uses [OpenVPN 2.4.6-r3 ](https://pkgs.alpinelinux.org/package/v3.8/main/x86_64/openvpn ) to connect to PIA servers
- The firewall [IPtables 1.6.2-r0 ](https://pkgs.alpinelinux.org/package/v3.8/main/x86_64/iptables ) enforces the container to communicate only through the VPN or with other containers in its virtual network
- Your DNS queries are encrypted using [Unbound 1.7.3-r0 ](https://pkgs.alpinelinux.org/package/v3.8/main/x86_64/unbound ) configure with Cloudflare's 1.1.1.1 DNS over TLS
- Malicious domain names resolution is blocked with [Unbound 1.7.3-r0 ](https://pkgs.alpinelinux.org/package/v3.8/main/x86_64/unbound )
- Lightweight, based on [Alpine 3.8 ](https://alpinelinux.org )
- Restarts OpenVPN on failure using another IP address corresponding to the PIA server domain name (usually 10 IPs per subdomain name)
- Regular Docker healthchecks using wget on duckduckgo.com
- Connect other containers to it
2018-03-31 21:56:18 -04:00
2018-09-21 16:39:08 +02:00
## Requirements
2018-09-20 20:35:29 +02:00
2018-03-04 13:44:51 -05:00
- A Private Internet Access **username ** and **password ** - [Sign up ](https://www.privateinternetaccess.com/pages/buy-vpn/ )
2018-02-06 21:57:41 -05:00
- [Docker ](https://docs.docker.com/install/ ) installed on the host
2018-09-21 16:39:08 +02:00
- If you use an advanced firewall:
2018-09-28 19:51:30 +02:00
- Allow outgoing TCP port 853 for Cloudflare DNS over TLS initial resolution of PIA server domain name.
- Allow outgoing TCP port 443 for querying duckduckgo to obtain the initial IP address for the healthcheck.
2018-09-21 16:39:08 +02:00
- Allow outgoing TCP port 501 for TCP strong encryption
- Allow outgoing TCP port 502 for TCP normal encryption
- Allow outgoing UDP port 1197 for UDP strong encryption
- Allow outgoing UDP port 1198 for UDP normal encryption
2018-02-06 21:57:41 -05:00
2018-04-15 14:15:58 -04:00
## Setup
2018-02-06 21:57:41 -05:00
2018-06-01 16:04:13 -04:00
1. Make sure you have your `/dev/net/tun` device setup on your host with one of the following commands, depending on your OS:
2018-06-01 14:38:27 -04:00
2018-09-20 20:35:29 +02:00
```bash
insmod /lib/modules/tun.ko
```
Or
```bash
sudo modprobe tun
```
2018-06-01 14:38:27 -04:00
2018-04-13 15:35:31 -04:00
1. Create a network to be used by this container and other containers connecting to it with:
```bash
docker network create pianet
```
2018-02-21 11:55:45 -05:00
2018-03-31 20:33:45 -04:00
1. Create a file * auth.conf * in `/yourhostpath` (for example), with:
2018-02-06 21:57:41 -05:00
- On the first line: your PIA username (i.e. `js89ds7` )
- On the second line: your PIA password (i.e. `8fd9s239G` )
2018-04-15 14:15:58 -04:00
2018-06-03 18:05:10 -04:00
### Option 1: Using Docker only
2018-03-31 20:33:45 -04:00
2018-04-15 14:15:58 -04:00
1. Run the container with (at least change `/yourhostpath` to your actual path):
2018-02-21 11:55:45 -05:00
2018-04-15 14:15:58 -04:00
```bash
2018-06-03 18:05:10 -04:00
docker run -d --name=pia \
2018-09-20 20:35:29 +02:00
--cap-add=NET_ADMIN --device=/dev/net/tun --network=pianet \
-v /yourhostpath/auth.conf:/auth.conf:ro \
2018-04-15 14:15:58 -04:00
-e REGION=Germany -e PROTOCOL=udp -e ENCRYPTION=normal \
qmcgaw/private-internet-access
```
2018-02-21 11:55:45 -05:00
2018-09-20 20:35:29 +02:00
Note that you can change `REGION` , `PROTOCOL` and `ENCRYPTION` , see the [Environment variables section ](#environment-variables ) for more.
2018-04-15 14:15:58 -04:00
1. Wait about 5 seconds for it to connect to the PIA server. You can check with:
2018-02-21 11:55:45 -05:00
2018-04-15 14:15:58 -04:00
```bash
docker logs pia
```
2018-02-21 11:55:45 -05:00
2018-04-15 14:15:58 -04:00
1. Follow the [**Testing section** ](#testing )
2018-02-21 11:55:45 -05:00
2018-06-03 18:05:10 -04:00
### Option 2: Using Docker Compose
2018-03-31 20:33:45 -04:00
1. Download [**docker-compose.yml** ](https://github.com/qdm12/private-internet-access-docker/blob/master/docker-compose.yml )
2018-04-15 14:15:58 -04:00
1. Edit it and change at least `yourpath`
2018-03-31 20:33:45 -04:00
1. Run the container as a daemon in the background with:
2018-09-20 20:35:29 +02:00
```bash
2018-03-31 20:33:45 -04:00
docker-compose up -d
```
2018-09-20 20:35:29 +02:00
Note that you can change `REGION` , `PROTOCOL` and `ENCRYPTION` , see the [Environment variables section ](#environment-variables ) for more.
2018-04-15 14:15:58 -04:00
1. Wait about 5 seconds for it to connect to the PIA server. You can check with:
2018-04-13 15:35:31 -04:00
```bash
2018-09-20 20:35:29 +02:00
docker logs -f pia
2018-04-13 15:35:31 -04:00
```
2018-09-20 20:35:29 +02:00
2018-04-15 14:15:58 -04:00
1. Follow the [**Testing section** ](#testing )
2018-04-13 15:35:31 -04:00
## Testing
2018-09-20 20:35:29 +02:00
1. Note that you can simply use the HEALTCHECK provided. The container will stop by itself if the VPN IP is the same as your initial public IP address.
2018-04-15 14:52:27 -04:00
Otherwise you can follow these instructions:
2018-03-31 20:33:45 -04:00
1. Check your host IP address with:
```bash
curl -s ifconfig.co
```
1. Run the **curl ** Docker container using your * pia * container with:
```bash
2018-06-06 22:44:11 -04:00
docker run --rm --network=container:pia byrnedo/alpine-curl -s ifconfig.co
2018-03-31 20:33:45 -04:00
```
2018-09-20 20:35:29 +02:00
If the displayed IP address appears and is different that your host IP address, the PIA client works !
2018-02-06 21:57:41 -05:00
2018-04-15 14:15:58 -04:00
## Environment variables
| Environment variable | Default | Description |
| --- | --- | --- |
| `REGION` | `Switzerland` | Any one of the [regions supported by private internet access ](https://www.privateinternetaccess.com/pages/network/ ) |
| `PROTOCOL` | `tcp` | `tcp` or `udp` |
| `ENCRYPTION` | `strong` | `normal` or `strong` |
2018-02-06 21:57:41 -05:00
2018-09-20 20:35:29 +02:00
If you know what you're doing, you can change the container name (`pia` ), the hostname (`piaclient` ) and the network name (`pianet` ) as well.
2018-02-21 11:55:45 -05:00
2018-04-13 15:35:31 -04:00
## Connect other containers to it
2018-09-20 20:35:29 +02:00
Connect other Docker containers to the PIA VPN connection by adding `--network=container:pia` when launching them.
2018-04-15 14:15:58 -04:00
---
2018-06-03 18:05:10 -04:00
2018-04-15 14:15:58 -04:00
## EXTRA: Access ports of containers connected to the VPN container
2018-02-21 11:55:45 -05:00
2018-09-20 20:35:29 +02:00
You have to use another container acting as a Reverse Proxy such as Nginx.
2018-02-21 11:55:45 -05:00
**Example**:
2018-09-20 20:35:29 +02:00
2018-06-03 18:05:10 -04:00
- We launch a * Deluge * (torrent client) container with name **deluge ** connected to the `pia` container with:
2018-09-20 20:35:29 +02:00
```bash
docker run -d --name=deluge --network=container:pia linuxserver/deluge
```
2018-06-03 18:05:10 -04:00
- We launch a * Hydra * container with name **hydra ** connected to the `pia` container with:
2018-09-20 20:35:29 +02:00
```bash
docker run -d --name=hydra --network=container:pia linuxserver/hydra
```
2018-06-03 18:05:10 -04:00
- HTTP User interfaces are accessible at port 8112 for Deluge and 5075 for Hydra
2018-04-13 15:35:31 -04:00
1. Create the Nginx configuration file * nginx.conf * :
2018-02-21 11:55:45 -05:00
2018-09-20 20:35:29 +02:00
```txt
2018-02-21 11:56:42 -05:00
user nginx;
worker_processes 1;
2018-02-21 11:55:45 -05:00
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
2018-02-21 11:56:42 -05:00
http {
2018-02-21 11:55:45 -05:00
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
server {
2018-06-03 18:05:10 -04:00
listen 1001;
2018-02-21 11:55:45 -05:00
location / {
proxy_pass http://deluge:8112/;
proxy_set_header X-Deluge-Base "/";
}
}
2018-06-03 18:05:10 -04:00
server {
listen 1002;
location / {
proxy_pass http://hydra:5075/;
}
}
2018-02-21 11:55:45 -05:00
include /etc/nginx/conf.d/*.conf;
}
```
2018-04-13 15:35:31 -04:00
1. Run the Alpine [Nginx container ](https://hub.docker.com/_/nginx ) with:
2018-02-21 11:55:45 -05:00
```bash
2018-06-03 18:05:10 -04:00
docker run -d --name=proxypia -p 8001:1001 -p 8002:1002 \
--network=pianet --link pia:deluge --link pia:hydra \
2018-02-21 11:55:45 -05:00
-v /mypathto/nginx.conf:/etc/nginx/nginx.conf:ro nginx:alpine
```
2018-06-03 18:05:10 -04:00
2018-04-13 15:35:31 -04:00
1. Access the WebUI of Deluge at [localhost:8000 ](http://localhost:8000 )
For more containers, add more `--link pia:xxx` and modify * nginx.conf * accordingly
2018-04-15 14:15:58 -04:00
## EXTRA: For the paranoids
2018-09-21 16:39:08 +02:00
- You might want to build the Docker image yourself
2018-04-15 14:15:58 -04:00
- The download and unziping is done at build for the ones not able to download the zip files with their ISPs.
- Checksums for PIA openvpn zip files are not used as these files change often
- You should use strong encryption for the environment variable `ENCRYPTION`
2018-09-21 16:39:08 +02:00
- Let me know if you have any extra idea :) !
2018-09-21 11:28:23 +02:00
### TODOs
2018-09-21 11:39:00 +02:00
- Block malicious websites with Unbound
- Add checks when launching PIA $?