HOW TO SETUP WIREGUARD + PiHOLE
Setting up the Server
Installation & System Setup
- Install wireguard on the server. More info here:
$ sudo apt install wireguard
Edit the file
/etc/sysctl.conf
and change and uncomment to the line that saysnet.ipv4.ip_forward=1
- Reboot the system or run the following command to activate the changes:
$ sysctl -p
Configuring Wireguard
- As
root
, create a file calledwg0.conf
in the/etc/wireguard/
folder: - You can generate a config at wireguardconfig.com
- Alternatively, you can do the following command to generate the public and private keys on your machine/server:
umask 077; wg genkey | tee privatekey | wg pubkey > publickey
- Here’s an example config:
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <SERVERPRIVATEKEY>
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey = <PEERPUBLICKEY>
AllowedIPs = 10.0.0.2/32
[Peer]
PublicKey = <PEERPUBLICKEY>
AllowedIPs = 10.0.0.3/32
Running Wireguard
- After the config is set up, run this from the
/etc/wireguard/
directory (you still need to beroot
):$ wg-quick up wg0
- You can check via:
$ wg
- Stop wireguard from the
/etc/wireguard/
directory via:$ wg-quick down wg0
Setting up the Client
- Follow the same install steps as in the server portion
- Modify your
wg0.conf
file to look like this:
[Interface]
Address = 10.0.0.2/24
ListenPort = 51820
PrivateKey = <YOURPRIVATEKEY>
DNS = 10.0.0.1
[Peer]
PublicKey = <SERVERPUBLICKEY>
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = <VPNURL_OR_IP>:51820
PersistentKeepalive = 30
Setting up Pihole
- Make sure
Docker
is installed on your server - Create a script file
createPiholeDocker.sh
with the following:
#!/bin/bash
# https://github.com/pi-hole/docker-pi-hole/blob/master/README.md
docker run -d \
--name pihole \
-p 10.0.0.1:53:53/tcp -p 10.0.0.1:53:53/udp \
-p 10.0.0.1:80:80 \
-p 10.0.0.1:443:443 \
-e TZ="America/Los_Angeles" \
-v "$(pwd)/etc-pihole/:/etc/pihole/" \
-v "$(pwd)/etc-dnsmasq.d/:/etc/dnsmasq.d/" \
--dns=127.0.0.1 --dns=1.1.1.1 \
--restart=unless-stopped \
pihole/pihole:latest
printf 'Starting up pihole container '
for i in $(seq 1 20); do
if [ "$(docker inspect -f "" pihole)" == "healthy" ] ; then
printf ' OK'
echo -e "\n$(docker logs pihole 2> /dev/null | grep 'password:') for your pi-hole: https://${IP}/admin/"
exit 0
else
sleep 3
printf '.'
fi
if [ $i -eq 20 ] ; then
echo -e "\nTimed out waiting for Pi-hole start start, consult check your container logs for more info (\`docker logs pihole\`)"
exit 1
fi
done;
- Make the script executable:
$ chmod +x createPiholeDocker.sh
- Run the script via:
$ ./createPiholeDocker.sh
- Verify Pihole is running via:
$ docker ps -a
Credits
Made with help from
WikiToDos:
Explain config files more (DNS Keep alive etc) - Fix Docker file/instructions
- Add info on Pihole DNS for easy computer access