Skip to the content.

Guide for Raspberrypi 3 to setup Openvpn + Pihole + DNS-over-HTTPS

1. Prerequisite

2. Install OS for Raspberry Pi

Read instruction at this page

3. Openvpn

curl -L https://install.pivpn.io | bash
sudo reboot

4. Pihole

For those who already installed pihole

For those who haven’t installed pihole yet.

Copy this command in terminal.

curl -sSL https://install.pi-hole.net | bash

Choose an Interface

Interface Make sure choose tun0.

Choose DNS Provider

DNS You can choose anything you want.

Choose Protocol

Protocol

Choose IP address

IP address Make sure IP address matches with your Pi and Gateway matches with your router.

Web Admin Interface and log queries

You should choose on to easy manage logs.

5. Setup OpenVPN to run with Pihole

dev tun
proto udp
port 11943
ca /etc/openvpn/easy-rsa/pki/ca.crt
cert /etc/openvpn/easy-rsa/pki/issued/server_ow2eJpQfeONY9S4s.crt
key /etc/openvpn/easy-rsa/pki/private/server_ow2eJpQfeONY9S4s.key
dh none
topology subnet
server 10.8.0.0 255.255.255.0
### Requirement
# server and remote endpoints
ifconfig 10.8.0.1 10.8.0.2
# Set your primary domain name server address for clients
push "route 10.8.0.1 255.255.255.255"
push "route 10.8.0.0 255.255.255.0"
push "route 192.168.x.x 255.255.255.255" # Change to your Pi's IP adress 
push "dhcp-option DNS 192.168.x.x" # Change to your Pi's IP adress
###
# Prevent DNS leaks on Windows
push "block-outside-dns"
# Override the Client default gateway by using 0.0.0.0/1 and
# 128.0.0.0/1 rather than 0.0.0.0/0. This has the benefit of
# overriding but not wiping out the original default gateway.
push "redirect-gateway def1"
client-to-client
keepalive 10 120
remote-cert-tls client
tls-version-min 1.2
tls-crypt /etc/openvpn/easy-rsa/pki/ta.key
cipher AES-256-CBC
auth SHA256
compress lz4
user nobody
group nogroup
persist-key
persist-tun
crl-verify /etc/openvpn/crl.pem
status /var/log/openvpn-status.log 20
status-version 3
syslog
verb 3
#DuplicateCNs allow access control on a less-granular, per user basis.
#Remove # if you will manage access by user instead of device. 
#duplicate-cn
# Generated for use by PiVPN.io

6. DNS-over-HTTPS [Optional]

cd ~
wget https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-arm.tgz
mkdir argo-tunnel
tar -xvzf cloudflared-stable-linux-arm.tgz -C ./argo-tunnel
rm cloudflared-stable-linux-arm.tgz
sudo cp ./argo-tunnel/cloudflared /usr/local/bin/
sudo /usr/local/bin/cloudflared proxy-dns --port 54 --upstream https://1.1.1.1/.well-known/dns-query --upstream https://1.0.0.1/.well-known/dns-query

cloudflare

sudo nano /etc/systemd/system/dnsproxy.service
[Unit]
Description=CloudFlare DNS over HTTPS Proxy
Wants=network-online.target
After=network.target network-online.target
 
[Service]
ExecStart=/usr/local/bin/cloudflared proxy-dns --port 54 --upstream https://1.1.1.1/.well-known/dns-query --upstream https://1.0.0.1/.well-known/dns-query
Restart=on-abort
 
[Install]
WantedBy=multi-user.target
sudo systemctl enable dnsproxy.service

7. Setup Pihole to run with DNS-over-HTTPS

Warning Pihole 4.0 and up

If you want to show block page, follow this configuration https://docs.pi-hole.net/ftldns/blockingmode/

8. Pihole 5.0 and up Export Blocklist to use anywhere.

Next - Oracle Cloud to setup Openvpn + Pihole