Hosts: Block the bullshit web V2
Advertisements, tracking scripts, and other countless lines of code downloaded on to your machine to spam and monitor you whenever you connect to the internet.
Host is a project to block advertisements, tracking scripts, and other websites including pornographic content.
We will use Pi-Hole as our DNS resolver which will be tunnelled via OpenVPN. Both the applications will be hosted on Oracle Cloud.
Step-by-step guide
Caution: We will enable the root access for convenience, which is strongly discouraged. If you are familiar with SSH, then I recommend using this approach. Please proceed with caution.
Instructions
I have covered only configuration changes, and suggest leaving the rest as untouched/recommended/system default.
This guide is written from Ubuntu OS perspective. [Note: This guide's previous version was for Windows. However, as of 22nd of October 2023, I am updating this for Ubuntu]
Set up an instance
Create an Oracle Cloud free tier: https://www.oracle.com/cloud/free
Setup an instance
Switch the OS from Oracle Linux to Ubuntu
Download and save the default generated a) public and b) private keys [Important to later access your server]
Note down Public IP and Private IP
Log in to Shell and switch to root: sudo su - root
Change root password: passwd root
[Note: The common practice is not to do this. Here the use case is security vs. convenience, where this approach is convenient but may be risky to permit remote access via root]
Install nano text editor (or your favourite alternative): sudo apt install nano -y
Search Internet on Oracle web GUI
Navigate to > Internet Gateway vcn-XXXXXXXX-XXXX
Left column > Navigate to > Security Lists
Navigate to > Default Security List for vcn-XXXXXXXX-XXXX
Add Ingress Rules
Source CIDR: 0.0.0.0/0
IP Protocol: UDP
Destination Port Range: 1194 [Step 20]
Login to the server
Open Terminal at local
From Terminal, navigate to the folder with Private key
Execute the following command in the directory: ssh -i <private key file name> <server username>@<public IP>
We will execute in the root mode: sudo su - root
Install and configure Pi-Hole
Install and configure Pi-Hole: https://github.com/pi-hole/pi-hole/#one-step-automated-install
Select interface: tun0
Change the Pi-Hole password: sudo pihole -a -p
Configure block lists
I suggest using the OISD block list, which covers almost every sub-list known to humankind: https://oisd.nl/ [follow instructions on the website and pick on need basis]
Pi-Hole supports multiple block lists. You can even curate your own list
Install and configure OpenVPN
Install and configure OpenVPN server using the following script: https://github.com/angristan/openvpn-install
Select Port: 1194
Create a default client after installation and download it [Step 30]
Edit the SSH config file: sudo nano /etc/ssh/sshd_config
Change following entries
PasswordAuthentication no > PasswordAuthentication yes
PermitRootLogin prohibit-password > PermitRootLogin yes
[Note: As mentioned earlier, do this at your own risk - this method allows you to easily connect to VM and grab any file from anywhere but this may pose a security risk]
Point the server/VPN to detect Pi-Hole as DNS server: sudo nano /etc/openvpn/server.conf
Change push "dhcp-option DNS <pihole private IP>"
Restart sshd: sudo systemctl restart sshd
Restart the VM from the Console
CRUD client profiles
Pre-requisite: Login as per step 10 to 14
To add/revoke OpenVPN client certificates aka profiles: ./openvpn-install.sh
After creating a new client certificate, to copy the certificate to Home directory to download via Remmina
cp /root/<client profile name>.ovpn /home
Login to Remmina [via Private key] and navigate to /home and download the client certificates to local
Load the client certificate in OpenVPN app on your device, connect to the VPN and enjoy [OpenVPN client for your device: https://openvpn.net/vpn-client]
Accessing Pi-Hole admin and maintenance
Access Pi-Hole web interface/dashboard
Connect to OpenVPN [Client certificate as per step 31]
Open your web browser and navigate to: https://<private ip>/admin [Password as per step 13]
Use following commands for periodic updates
Pre-requisite: Login as per step 10 to 14
Ubuntu: apt update && apt upgrade && apt dist-upgrade
OpenVPN: apt update && apt upgrade
Pi-Hole: pihole -up
Pi-Hole Gravity (adblock lists): pihole -g
Restart after update: reboot
Optional: to auto connect VPN on Ubuntu by executing the following command in the terminal: nm-connection-editor
Shortcut to toggle VPN: Settings > Keyboard > View and customise shortcuts > Custom shortcuts > a) Toggle VPN off: nmcli con down <VPN profile name> and b) Toggle VPN on: nmcli con up <VPN profile name>.
One of the feedbacks out of many.