Pi-hole on Ubuntu Server

Pi-hole is a powerful network-wide ad blocker that acts as a DNS sinkhole. It helps block intrusive ads, trackers, and other unwanted content at the network level, preventing them from ever reaching your devices. This can be especially helpful for improving privacy, speeding up browsing, and reducing distractions. In this guide, we will walk you through the installation of Pi-hole on an Ubuntu server and show you how to check the total number of ads blocked using a simple command.

Prerequisites

  • An Ubuntu server (version 18.04 or newer is recommended).
  • A static IP address configured for your server (Pi-hole should have a fixed IP to function as a DNS server).
  • A user with sudo privileges.

Step 1: Update Your System

Before starting the installation process, it’s always a good idea to ensure that your system is up-to-date. Run the following commands to update your Ubuntu server:

sudo apt update && sudo apt upgrade -y

This ensures that all packages and security patches are installed, minimizing the chance of issues during installation.

Step 2: Install Pi-hole

Pi-hole provides an easy-to-use installation script that automates the setup process. To install Pi-hole, run the following command:

curl -sSL https://install.pi-hole.net | bash

This command downloads and executes the official Pi-hole installation script. Once you run the command, you will be prompted to follow a series of interactive setup steps.

Step 3: Configure Pi-hole

During the installation process, you will be asked to configure various options:

  • Upstream DNS provider: Pi-hole will need to know which DNS provider it should use for resolving domains that are not blocked. You can choose from several popular options like Google, OpenDNS, or Cloudflare.
  • Static IP address: Pi-hole needs a static IP to function correctly as a network-wide DNS server. Make sure your server has a static IP address assigned.
  • Web Admin Interface: Pi-hole includes a powerful web-based interface that allows you to monitor and configure its settings. You will be asked if you want to install this feature. It is highly recommended to enable it for easier management.
  • DHCP Server: Pi-hole can also act as a DHCP server. You can enable this feature if you want Pi-hole to assign IP addresses to devices on your network.

Step 4: Access the Pi-hole Admin Interface

Once the installation is complete, you can access Pi-hole’s web interface by navigating to the following URL in a web browser:

http://<your-server-ip>/admin

You will be prompted to log in using the password generated during the installation process. Once logged in, you can view statistics, manage blocklists, and configure additional settings.

Step 5: Set Your Devices to Use Pi-hole

To start benefiting from Pi-hole’s ad-blocking features, you need to set your devices (e.g., computers, smartphones, smart TVs) to use the Pi-hole server as their DNS server.

  • Option 1: Set the DNS server manually on each device. Go to the network settings of each device and configure it to use the IP address of your Pi-hole server.
  • Option 2: Configure your router to distribute Pi-hole as the DNS server to all devices connected to your network. This will ensure that any new device that joins the network uses Pi-hole for DNS resolution by default.

Step 6: Monitor Ads Blocked

Pi-hole provides real-time statistics on the number of ads blocked across your entire network. To view the total number of ads blocked, you can use a simple SQLite command.

Pi-hole stores its data, including the number of ads blocked, in a SQLite database. You can query this database using the sqlite3 command. Here’s how to check the total number of ads blocked:

  1. Open a terminal on your Ubuntu server.
  2. Run the following command:
sudo sqlite3 /etc/pihole/pihole-FTL.db "SELECT value FROM counters WHERE id = 1"

This command queries the Pi-hole database for the number of blocked ads. The result will be a single value that represents the total number of ads that Pi-hole has blocked since its installation.

Understanding the Command

  • sudo sqlite3 /etc/pihole/pihole-FTL.db: This part of the command opens the Pi-hole database (pihole-FTL.db) using the SQLite tool with sudo privileges.
  • "SELECT value FROM counters WHERE id = 1": This SQL query retrieves the value from the counters table, specifically the row with id = 1, which corresponds to the total number of ads blocked.

Example Output

After running the command, you may see an output like:

1234567

This number represents the total number of ads that Pi-hole has blocked so far.

Step 7: Additional Features

Pi-hole offers many additional features that can enhance your experience:

  • Blocklists: You can add custom blocklists to Pi-hole to block more ads and trackers. There are many publicly available blocklists you can integrate into Pi-hole.
  • Query Logging: Pi-hole logs every DNS query made by your devices. You can view detailed logs through the web interface or use the pihole -t command for live monitoring.
  • Whitelist & Blacklist: You can manually whitelist or blacklist domains through the web interface or using the pihole command-line tool.

Conclusion

Pi-hole is an excellent tool for blocking ads and improving privacy on your network. By installing Pi-hole on an Ubuntu server, you can enjoy a more streamlined and efficient browsing experience across all devices on your network. Additionally, you can monitor its performance and track the number of ads blocked using simple commands like the one provided above.

If you follow these steps, you should have Pi-hole up and running in no time, helping you to reduce unwanted ads and enhance your online privacy.

Similar Posts

  • Ticker for Terminal

    The Ticker program is a powerful command-line tool. It tracks real-time stock and cryptocurrency prices directly within the Ubuntu Server terminal. It allows users to monitor market activity without needing a graphical interface. This makes it ideal for server environments or lightweight…

  • Ubuntu Server Programs

    This is list of programs I use on my Ubuntu Servers with some very basic information. Some of my favorite and most useful Ubuntu Server programs include Network-Tools, Ranger, TMUX, and CMUS for efficient terminal-based management. Network-Tools helps with quick network diagnostics,…

  • Two-Line Prompt

    To have your terminal show the input command on its own line, with your username and the current working directory (PWD) on a separate line, you will need to modify the shell prompt (PS1) in your terminal configuration. Here’s how you can…

  • TMUX

    TMUX is an easy to use Terminal Multiplexer where users can split the Terminal CLI (Command Line Interface) into multiple mini Terminals. Here’s a TMUX Cheat Sheet with essential tmux commands: Installing tmux The following command installs tmux from the snap repositories….