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-11-06 14:55:11 +01:00
*Lightweight VPN client to tunnel to private internet access servers*
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-10-29 16:32:11 +01: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-10-29 16:32:11 +01:00
| Image size | RAM usage | CPU usage |
| --- | --- | --- |
2019-01-01 23:14:36 +02:00
| 19.1MB | 14MB to 80MB | Low to Medium |
2018-04-15 14:15:58 -04:00
2018-10-29 16:32:11 +01:00
It is based on:
- [Alpine 3.8 ](https://alpinelinux.org ) for a tiny image
- [OpenVPN 2.4.6-r3 ](https://pkgs.alpinelinux.org/package/v3.8/main/x86_64/openvpn ) to tunnel to PIA servers
2018-11-06 14:55:11 +01:00
- [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 (acts as a killswitch)
2018-10-29 16:32:11 +01:00
- [Unbound 1.7.3-r0 ](https://pkgs.alpinelinux.org/package/v3.8/main/x86_64/unbound ) configured with Cloudflare's [1.1.1.1 ](https://1.1.1.1 ) DNS over TLS
2019-01-01 23:14:36 +02:00
- [Files and blocking lists built periodically ](https://github.com/qdm12/updated/tree/master/files ) used with Unbound (see `BLOCK_MALICIOUS` environment variable)
2018-10-29 16:32:11 +01:00
## Extra features
2018-09-20 20:35:29 +02:00
2018-11-14 14:38:10 +02:00
- Only use environment variables:
2019-01-01 23:14:36 +02:00
- the [destination region ]((https://www.privateinternetaccess.com/pages/network/ ))
- the protocol `tcp` or `udp`
- the level of encryption `normal` or `strong`
2018-09-21 16:39:08 +02:00
- Connect other containers to it
2018-11-06 14:55:11 +01:00
- The * iptables * firewall allows traffic only with needed PIA servers (IP addresses, port, protocol) combination
2018-11-14 14:38:10 +02:00
- OpenVPN restarts on failure using another PIA IP address for the same region
2018-11-14 16:25:23 +02:00
- Docker healthchecks using [duckduckgo.com ](https://duckduckgo.com ) to obtain your public IP address and compare it with PIA Ips in configuration file
2018-10-29 16:32:11 +01:00
- Openvpn and Unbound do not run as root
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-11-14 16:25:23 +02:00
- If you use a strict firewall on the host/router:
- Allow outbound TCP 853 to 1.1.1.1 to allow Unbound to resolve the PIA domain name at start. You can then block it once the container is started.
- For UDP strong encryption, allow outbound UDP 1197
- For UDP normal encryption, allow outbound UDP 1198
- For TCP strong encryption, allow outbound TCP 501
- For TCP normal encryption, allow outbound TCP 502
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
2018-11-14 14:38:10 +02:00
modprobe tun
2018-04-13 15:35:31 -04:00
```
2018-02-21 11:55:45 -05:00
2018-10-29 16:32:11 +01:00
1. Launch the container with:
2018-02-21 11:55:45 -05:00
2018-04-15 14:15:58 -04:00
```bash
2018-10-29 16:32:11 +01:00
docker run -d --name=pia -v ./auth.conf:/auth.conf:ro \
2018-09-20 20:35:29 +02:00
--cap-add=NET_ADMIN --device=/dev/net/tun --network=pianet \
2018-10-29 16:32:11 +01:00
-e REGION="CA Montreal" -e PROTOCOL=udp -e ENCRYPTION=strong \
2018-11-14 14:38:10 +02:00
-e USER=js89ds7 -e PASSWORD=8fd9s239G \
2018-04-15 14:15:58 -04:00
qmcgaw/private-internet-access
```
2018-02-21 11:55:45 -05:00
2018-10-29 16:32:11 +01:00
or use [docker-compose.yml ](https://github.com/qdm12/private-internet-access-docker/blob/master/docker-compose.yml ) with:
2018-03-31 20:33:45 -04:00
2018-09-20 20:35:29 +02:00
```bash
2018-03-31 20:33:45 -04:00
docker-compose up -d
```
2018-11-14 14:38:10 +02:00
Note that you can change all the [environment variables ](#environment-variables )
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-11-14 16:25:23 +02:00
You can simply use the Docker healthcheck. The container will mark itself as **unhealthy ** if the public IP address is not part of the PIA IPs. Otherwise you can follow these instructions:
2018-04-15 14:52:27 -04:00
2018-03-31 20:33:45 -04:00
1. Check your host IP address with:
```bash
2018-10-29 16:32:11 +01:00
wget -qO- https://ipinfo.io/ip
2018-03-31 20:33:45 -04:00
```
2018-11-06 14:55:11 +01:00
1. Run the same command in a Docker container using your * pia * container as network with:
2018-03-31 20:33:45 -04:00
```bash
2018-10-29 16:32:11 +01:00
docker run --rm --network=container:pia alpine:3.8 wget -qO- https://ipinfo.io/ip
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 |
| --- | --- | --- |
2018-11-14 14:38:10 +02:00
| `REGION` | `CA Montreal` | One of the [PIA regions ](https://www.privateinternetaccess.com/pages/network/ ) |
2018-10-29 16:32:11 +01:00
| `PROTOCOL` | `udp` | `tcp` or `udp` |
2018-04-15 14:15:58 -04:00
| `ENCRYPTION` | `strong` | `normal` or `strong` |
2018-10-29 16:32:11 +01:00
| `BLOCK_MALICIOUS` | `off` | `on` or `off` |
2019-01-14 09:55:14 +01:00
| `USER` | | Your PIA username |
| `PASSWORD` | | Your PIA password |
| `EXTRA_SUBNETS` | | Comma separated subnets allowed in the container firewall |
2018-02-06 21:57:41 -05:00
2018-11-14 14:38:10 +02:00
`EXTRA_SUBNETS` can be in example: `192.168.1.0/24,192.168.10.121,10.0.0.5/28`
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-11-20 09:27:10 +02:00
For containers in the same `docker-compose.yml` as PIA, you can use `network: "service:pia` (see below)
2018-11-18 19:31:09 +02:00
2018-11-20 09:27:10 +02:00
### Access ports of PIA-connected containers
#### General case
1. For example, the following containers are launched connected to PIA:
2018-11-18 19:31:09 +02:00
```bash
docker run -d --name=deluge --network=container:pia linuxserver/deluge
docker run -d --name=hydra --network=container:pia linuxserver/hydra
```
We want to access:
- The HTTP web UI of Deluge at port **8112 **
- The HTTP Web UI of Hydra at port **5075 **
1. In this case we use Nginx for its small size. Create `./nginx.conf` with:
```bash
# nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 64;
}
http {
server {
listen 8000;
location /deluge {
proxy_pass http://deluge:8112/;
proxy_set_header X-Deluge-Base "/deluge";
}
}
server {
listen 8001;
location / {
proxy_pass http://hydra:5075/;
}
}
}
```
1. Run the [Nginx Alpine container ](https://hub.docker.com/_/nginx ):
```bash
docker run -d -p 8001:8001/tcp -p 8002:8002/tcp \
--link pia:deluge --link pia:hydra \
-v $(pwd)/nginx.conf:/etc/nginx/nginx.conf:ro \
nginx:alpine
```
**WARNING ** : Make sure the Docker network in which Nginx runs is the same as the one of PIA. It can be the default `bridge` network.
1. Access the WebUI of Deluge at [localhost:8000 ](http://localhost:8000 ) and Hydra at [localhost:8001 ](http://localhost:8001 )
For more containers, add more `--link pia:xxx` and modify * nginx.conf * accordingly
2018-11-20 09:27:10 +02:00
#### Containers with PIA in one docker-compose.yml
This is simpler but restrictive in terms of management as all containers must be in the same * docker-compose.yml * .
For example, the following file
```yml
version: '3'
services:
pia:
build: https://github.com/qdm12/private-internet-access-docker.git
image: qmcgaw/private-internet-access
container_name: pia
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun
network_mode: bridge
ports:
- 8112:8112/tcp
environment:
- USER=js89ds7
- PASSWORD=8fd9s239G
- PROTOCOL=udp
- ENCRYPTION=strong
- REGION=CA Montreal
- EXTRA_SUBNETS=
restart: always
deluge:
image: linuxserver/deluge
depends_on:
- pia
network_mode: "service:pia"
restart: always
```
will publish port 8112 as Deluge WebUI without any trouble.
2018-11-14 14:38:10 +02:00
## For the paranoids
2018-02-21 11:55:45 -05:00
2018-11-14 14:38:10 +02:00
- You can review the code which essential consits in the [Dockerfile ](https://github.com/qdm12/private-internet-access-docker/blob/master/Dockerfile ) and [entrypoint.sh ](https://github.com/qdm12/private-internet-access-docker/blob/master/entrypoint.sh )
- Build the images yourself:
2018-06-03 18:05:10 -04:00
2018-09-20 20:35:29 +02:00
```bash
2018-11-14 14:38:10 +02:00
docker build -t qmcgaw/private-internet-access https://github.com/qdm12/private-internet-access-docker.git
2018-09-20 20:35:29 +02:00
```
2018-06-03 18:05:10 -04:00
2018-11-14 14:38:10 +02:00
- The download and unziping of PIA openvpn files is done at build for the ones not able to download the zip files
- Checksums for PIA openvpn zip files are not used as these files change often (but HTTPS is used)
- Use `-e ENCRYPTION=strong -e BLOCK_MALICIOUS=on`
2018-09-21 11:28:23 +02:00
2018-10-29 16:32:11 +01:00
## TODOs
2018-11-20 09:27:10 +02:00
- [ ] Nginx scratch
2018-11-14 14:38:10 +02:00
- [ ] SOCKS proxy/Hiproxy/VPN server for other devices to use the container
2018-11-20 09:27:10 +02:00
- [ ] Port forwarding
2018-10-29 16:32:11 +01:00
## License
2018-09-21 11:28:23 +02:00
2018-10-29 17:03:24 +01:00
This repository is under an [MIT license ](https://github.com/qdm12/private-internet-access-docker/master/license )