Skip to content

Instantly share code, notes, and snippets.

@minlaxz
Last active March 14, 2021 16:14
Show Gist options
  • Save minlaxz/a844d546b6398215f3a5f4a93df078cd to your computer and use it in GitHub Desktop.
Save minlaxz/a844d546b6398215f3a5f4a93df078cd to your computer and use it in GitHub Desktop.
OVPN-PiHole-Docker

SSH into AWS ec2/ Digitalocean droplet/ or else other PAAS, linux machine

  1. Install Docker
$ curl -sS get.docker.com | sh
$ sudo usermod -aG docker $USER
  1. Install Open VPN
$ docker volume create --name ovpn-data
$ docker network create --driver=bridge   --subnet=172.20.0.0/24 --gateway=172.20.0.1 vpn-network
# server ip=52.66.18.251
$ docker run -v ovpn-data:/etc/openvpn --rm myvpn ovpn_genconfig -u udp://52.66.18.251:PORT
# Certificate Generation take 2-5 minutes.
$ docker run -v ovpn-data:/etc/openvpn --rm -it myvpn ovpn_initpki

Openvpn running in port 1194

$docker run -v ovpn-data:/etc/openvpn --name openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN myvpn

Create User "test" without Password, use the keypharse used in certificate generation

$docker run -v ovpn-data:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full test nopass

Download the "test.ovpn" from docker volume to local volume

$docker run -v ovpn-data:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient test > test.ovpn

download the key to your laptop install openvpn client for windows

check openvpn, by connecting to vpn

  1. Install Pihole

change pihole web ui in port 8080

$ docker run -it -p 53:53/tcp -p 53:53/udp -p 8080:80   --cap-add=NET_ADMIN   -e ServerIP=52.66.18.251   --name pihole  diginc/pi-hole:debian

pihole is running at pot 8080 but isn't configured to openvpn get pihole ip

$ docker inspect pihole

for me 172.17.0.3

4.OpenVPN+Pihole

$docker exec -it openvpn /bin/bash
$export TERM=xterm
$apk update 
$apk add nano 
$nano /etc/openvpn/openvpn.conf
### Push Configurations Below
push block-outside-dns
push dhcp-option DNS 172.17.0.3
#push dhcp-option DNS 8.8.4.4

ctrl+x to save

before restarting openvpn go to youtube.com, you will see advertisement in homepage

  1. finally restart openvpn
$docker restart openvpn

reload youtube.com

go to youtube.com, you will see advertisement blocked in homepage enjoy, thanks watching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment