Pi-hole is a network-wide ad blocking that will work as our preferred DNS server to block undesired queries to internet domains which only provides advertisements, and OpenVPN will help us to connect straightly to our house’s local network via VPN tunnel.
Both servers are really easy to install and configure trough their installation wizard, we are going to start with the VPN:
Installing the OpenVPN server
First of all, download the OpenVPN installer,
wget https://git.io/vpn -O openvpn-install.sh
make it executable
sudo chmod a+x openvpn-install.sh
and run it,
enter your raspberry’s IP address and accept all the defaults,
Which DNS do you want to use with the VPN? 1) Current system resolvers 2) Google 3) OpenDNS 4) NTT 5) Hurricane Electric 6) Verisign DNS [1-6]: 1
Next, install Pi-hole and choose
tun0 as interface. You can accept all the defaults except the interface, it must be
tun0 or it won’t work properly.
curl -sSL https://install.pi-hole.net | bash
Let’s setup both instances to work together!
First, look for the IP of your
tun0 interface, it should be 10.8.0.1 by default,
ifconfig tun0 | grep 'inet addr'
edit the OpenVPN configuration to set up the Pi-hole DNS server as VPN default DNS server.
sudo nano /etc/openvpn/server.conf
Set this line for use our Pi-hole server (the IP from the ifconfig command output or 10.8.0.1),
push "dhcp-option DNS 10.8.0.1" #push "dhcp-option DNS 220.127.116.11"
After that, just restart the VPN to apply the new configuration,
service openvpn restart
Now that everything is set up, let’s create a profile for the VPN, you can execute it to make as many client connections as you need. Run the VPN installer again,
Choose “add a new user” and write down a client name, this procedure will generate a .
ovpn which must be copied on your client machine and you’ll be able to block ads anywhere.
If you want some more tutorials about Raspberry Pi, please check my blog posts.
For further information, you can visit Pi-hole’s project web page.