Initial Setup
This document serves as a technical reference for configuring a Pi-hole and OpenVPN setup. Users are encouraged to replicate the steps outlined herein.
-
Follow the Pi-hole VPN Guide:
- Access the guide here.
- In the initial command, replace
wget https://git.io/vpn -O openvpn-install.shwithwget https://git.hhf.technology/hhf/OpenVPN-install/raw/branch/main/openvpn-install.sh -O openvpn-install.sh. This change directs to a more secure fork of installer. - Utilize the default options unless specific configurations are required (e.g., choose between
tun0andeth0based on your network architecture). - Depending on privacy considerations and the current status of FTLDNS, it may be prudent to disable DNS logging options.
- Ensure that
iptablesis configured to reload upon system restart by executingsudo bash -c "iptables-save > /etc/iptables.conf"and addingiptables-restore < /etc/iptables.confto/etc/rc.local. - If operating in a hosted environment, consider opting out of static IP allocation; this may facilitate server restoration under different IP addresses (this remains untested).
- For internal network setups, implement the following:
- Refer to the optional guides for Dual Operation: LAN & VPN and Dynamic DNS (omit
<b> </b>tags in the dual operation section). - Configure a static/reserved IP for the Pi-hole device and forward port 1194 in your router settings.
- Refer to the optional guides for Dual Operation: LAN & VPN and Dynamic DNS (omit
- Users may experience slow connection speeds upon VPN initiation. To mitigate this, append
tun-mtu 1400andmssfix 1360at the end of/etc/openvpn/server.conf.
-
Implementing DNS Over HTTPS:
- Until native functionality is integrated into FTLDNS, utilize Cloudflare’s encrypted DNS protocol via DNS over HTTPS. Refer to Cloudflare’s documentation here.
- Follow either this tutorial or the official guide here.
- For domain management on DigitalOcean, create a subdomain for your VPN that points to a dynamic IP address. The following script can be utilized to update DNS records dynamically from your Pi-hole:
#!/bin/bash PUBLIC_IPV4=$(curl ifconfig.co) MY_API_ACCESS_TOKEN="your-api-key-from-https://cloud.digitalocean.com/settings/api/tokens" curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer ${MY_API_ACCESS_TOKEN}" -d '{"data":"'"${PUBLIC_IPV4}"'"}' "https://api.digitalocean.com/v2/domains/example.com/records/MY_DOMAIN_ID"Replace
example.comwith your domain name andMY_DOMAIN_IDcan be retrieved using:curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_API_ACCESS_TOKEN" "https://api.digitalocean.com/v2/domains/example.com/records"Ensure the script is executable and schedule it in
crontabusingcrontab -e.
Migration of OpenVPN Server and Pi-hole
In the event that the OpenVPN server and Pi-hole are relocated to a new IP address (note: this process remains untested):
-
Update the remote server IP in all existing client
.ovpnfiles/configurations as well as in/etc/openvpn/client-template.txt.- This step is unnecessary if utilizing DynamicDNS configured within these files.
- If using a domain name, ensure that DNS records are updated with your Domain Name Registrar.
-
For configurations involving Dual Operation: LAN & VPN, modify
/etc/openvpn/server.confto reflect new IP addresses in:push "route 192.168.0.0 255.255.255.0" push "dhcp-option DNS 192.168.0.35"Adjust these settings according to any changes in subnet.
-
Update
/etc/dhcpcd.confwith the new static IP address and gateway (available in DigitalOcean under settings > networking). Reboot and verify functionality; further adjustments may not be necessary. -
Modify the IPV4 address in
/etc/pihole/setupVars.conf, or alternatively executepihole -r. Note that reconfiguration will be required for the cloudflared service established earlier.- If executing
pihole -r, you will need to select a DNS server; subsequently, reconfigure Pi-hole to utilize the locally running cloudflared service as per this guide.
- If executing
-
Adjust any static IP configurations and OpenVPN port forwarding settings (typically on port 1194) in your new router.
-
If utilizing Dual Operation: LAN & VPN, ensure
/etc/iptables.confreflects any changes to local subnet configurations (e.g., from 192.168.0.0/24to192.168.1.0/24). -
Restart the Pi-hole device to apply all firewall changes effectively.