Skip to content

Instantly share code, notes, and snippets.

@g3rhard
Last active April 20, 2024 08:48
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save g3rhard/4085cf7876d1c0060a6e1fded3a4cac3 to your computer and use it in GitHub Desktop.
Save g3rhard/4085cf7876d1c0060a6e1fded3a4cac3 to your computer and use it in GitHub Desktop.
openvpn+pihole+docker (new docker-compose image - https://gist.github.com/g3rhard/4e300ba26d3839ffddc210ff9e1c68d6)

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

  1. Install Docker
$sudo apt install docker.io
$sudo usermod -aG docker $USER

I already installed docker

  1. Install Open VPN
$docker volume create --name ovpn-data
# server ip=52.66.18.251
$docker run -v ovpn-data:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://52.66.18.251
# Certificate Generation take 2-5 minutes.
$docker run -v ovpn-data:/etc/openvpn --rm -it kylemanna/openvpn 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 kylemanna/openvpn

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

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

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

$docker run -v ovpn-data:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient praba > praba.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

@aokomorowski
Copy link

@g3rhard
Copy link
Author

g3rhard commented Jul 10, 2019

https://masteringmarkdown.com/

This is an old note, now I use the Docker-compose bundle, like this
https://gist.github.com/g3rhard/4e300ba26d3839ffddc210ff9e1c68d6

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