In this guide, we will be installing PiHole in Ubuntu 18.04.
Pihole is an incredible easy to use and install AdBlocking Server with an easy to use web interface. PiHole works by replacing your current DNS server and uses multiple blocklists to block malicious DNS queries and AD Sites.
The Pi-hole can block ads for all devices on your network once it is set up in your routers config. This setup allows you to save bandwidth while also blocking known malicious sites.It can also block Pornography and unsafe sites by using readily available blocklists from around the web.
You can find more info on PiHole here or on their GitHub site here
Installation
Connect to your server as the admin user via SSH.
ssh [email protected]
Update and upgrade your web server
sudo apt update && sudo apt upgrade -y
Install all the required components
sudo apt install git -y
Set a static IP
sudo nano /etc/network/interfaces
Replace the following text
....
auto eth0
iface eth0 inet dhcp
....
With the following
.....
auto eth0
iface eth0 inet static
address 192.168.1.15
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
.....
Save file and reboot
sudo shutdown -r now
Connect to your server as the admin user via SSH to the newly set IP address.
ssh [email protected]
Now the installation begins
git clone --depth 1 https://github.com/pi-hole/pi-hole.git Pi-hole
cd Pi-hole/automated\ install/
bash basic-install.sh
Enter your account sudo password
Hit OK
Choose your favourite DNS provider. After testing all servers the fastest one for me was OpenDNS.
Choose wether or not you want a Web Interface (Recommended)
Logging should be enabled here if you are using a Web Interface
Hit Yes, to add firewall rules to allow TCP port 80 and TCP and UDP port 53 unfortunatelly these rules are not persistant in Ubuntu bellow you will find the correct way to open the required ports in case you have UFW firewall enabled
Take note of your Web Interface Password
Set a diffrent web interface password
sudo pihole -a -p
DnsMasq Fix:
Edit the Resolved.conf file to fix issue with DnsMasq failing to start
sudo nano /etc/systemd/resolved.conf
uncomment and change DNSStubListener=yes to DNSStubListener=no
....
[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
DNSStubListener=no
....
Control X + Y to save and exit
Reboot
sudo shutdown -r now
At this point the Web Interface works however if we have UFW firewall enabled here are the instruccions to open the required ports so this persist after reboot.
The following commands will open TCP port 80 for the web interface and TCP and UDP port 53 required by DNS
sudo ufw allow http
sudo ufw allow 53
Finally we need to change your routers DNS configuration to point to your PiHoles IP Address.
These changes differ from router to router.
Here are a couple of good resources to perform this change:
Finally Open your Web Interface at
http://your.server.ip/admin
Log in to the site
You can add additional blocklist from multiple sources to block even more sites with PiHole as shown below.
hosts files from several well-curated sources like adaway.org, mvps.org, malwaredomainlist.com, someonewhocares.org, and potentially others.