Skip to content

Instantly share code, notes, and snippets.

@minlaxz
Last active May 23, 2021 09:43
Show Gist options
  • Save minlaxz/825873975d97f1eeb99a75f61d869818 to your computer and use it in GitHub Desktop.
Save minlaxz/825873975d97f1eeb99a75f61d869818 to your computer and use it in GitHub Desktop.
Dockerizing OpenVPN with PiHole.

__This setup is working correctly on Ubuntu20-Server __ Assumming All These Commands are ran by Root User

  1. Git Clone Kylemanna/docker-openvpn git clone https://github.com/kylemanna/docker-openvpn.git && cd docker-openvpn

  2. Build OpenVPN docker image docker build -t IMAGE_NAME .

  3. Generate Config for OpenVPN docker run -v $PWD/etc-openvpn:/etc/openvpn --rm IMAGE_NAME ovpn_genconfig -u udp://$(curl text.wtfismyip.com):3000

  4. Initialize PKI (Initialise PKI) docker run -v $PWD/etc-openvpn:/etc/openvpn --rm -it IMAGE_NAME ovpn_initpki

  5. Generate a Strong Password When it prompt a password Enter step 5.a password. 65h%3$5^$$^#89 like this

  6. It will prompt for a name you call (any)

  7. Disable DNSStubListener sed -r -i.orig 's/#?DNSStubListener=yes/DNSStubListener=no/g' /etc/systemd/resolved.conf confirm DNSStubListener=no by nano /etc/systemd/resolved.conf

  8. Replace original resolv.conf sh -c 'rm /etc/resolv.conf && ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf'

  9. Restart systemd-resolved systemctl restart systemd-resolved

  10. Ensure 53 is not used by Any Process ss -tlnpw | grep 53

  11. Create a docker network docker network create --driver=bridge --subnet=172.20.0.0/24 --gateway=172.20.0.1 vpn-network

  12. docker-compose up -d

  13. docker exec -it openvpn ash

  14. #apk add nano && nano /etc/openvpn/openvpn.conf

  15. Comment out these lines # push "dns-option DNS 8.8.8.8" # push "dns-option DNS 8.8.4.4

  16. Add these lines push "dns-option DNS 172.20.0.2" push "dns-option DNS 1.1.1.1

  17. Generate a VPN profile (this will need step.5 password) docker run -v $PWD/etc-openvpn:/etc/openvpn --rm -it laxzvpn easyrsa build-client-full minlaxz nopass

  18. Generate ovpn file docker run -v $PWD/etc-openvpn:/etc/openvpn --rm laxzvpn ovpn_getclient minlaxz > minlaxz.ovpn

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