First run update packages and upgrade Ubuntu Server
sudo apt update && sudo apt upgrade -y
To check if curl is installed and functioning on Ubuntu Server 24.04, run the command
curl --version
If curl is not installed, run this command to install it:
sudo apt install curl -y
Next, Disable the default systemd-resolved DNS stub listener to free up Port 53 for Pi-hole. Then, restart systemd-resolved with the following commands:
sudo sed -i 's/#DNSStubListener=yes/DNSStubListener=no/' /etc/systemd/resolved.conf sudo systemctl restart systemd-resolved
Next intall Pi-Hole for standard bare metal server environments (not containerized) using the Official Automated Script – Run the official network installer command:
curl -sSL https://install.pi-hole.net | bash
OPTION: When installing on Ubuntu version 26.04, you will instead need to disable the Operating System version check when running the official network installer of Pi-Hole:
curl -sSL https://install.pi-hole.net | sudo PIHOLE_SKIP_OS_CHECK=true bash
Complete the Configuration of Pi-Hole.
Once the installation wizard launches in your terminal: Follow the on-screen prompts to choose an upstream DNS provider (such as Cloudflare or Google), or use the two DNS servers from your ISP.
Write down for safekeeping the Admin Web Interface Password displayed at the very end of the installation process. Then log into your dashboard by opening a web browser and navigating to:
http://<YOUR_SERVER_IP>/admin
IMPORTANT: You must change the port used to access Pi-Hole Admin dashboard if you want both Apache and the Pi-hole web dashboard to run on the same Ubuntu server. By default, both try to bind to Port 80, which will cause a conflict and prevent one of them from starting.
However, the official installer does not give you an option to change the port during the installation wizard. You must configure it immediately after the installation finished. Pi-hole v6 uses an embedded web server managed directly through pihole-FTL. If Apache is already active, the Pi-hole installer will finish, but its web service will fail to start. Fix this immediately after the installation script finishes:
sudo vim /etc/pihole/pihole.toml
Look for the [webserver] section and locate the port variable. Change 80 to an open port like 8080.
port = "8080o,443os,[::]:8080o,[::]:443os"
Save the file (Esc from Insert mode and type :w then Enter) and exit vim (:q! then enter). Restart the Pi-hole system service to apply changes:
sudo systemctl restart pihole-FTL
The Pi-Hole installer steps:
The installer will transform your device into a network-wide ad blocker!
The Pi-Hole is free but powered by your donations, https://pi-hole.net/donate
Pi-hole is a server and needs a static IP address to function properly. Please continue when the static addressing has been configured.
Select an upstream DNS provider:
There is a list and then there is “custom” so, select Custom and click ok.
Enter your desired Upstream DNS providers separated by a comma +1 space, for example: 8.8.8.8, 8.8.4.4
Confirm that your DNS entries are correct.
Do you want to use StevenBlack's Unified Host List (block list)? Yes or No. I selected No. You can add this later if you wish. Or add your own chosen block list later.
Would you like to enable Query Logging? Yes or No. I selected No.
Select a privacy mode for FTL. With my mouse, I chose: 3 - Anonymous Mode and Continue
See: https://docs.pi-hole.net/ftldns/privacylevels.
INSTALL RESULTS:
[i] SELinux not detected [✓] Update local cache of available packages [✓] Building dependency package pihole-meta.deb [✓] Installing Pi-hole dependency package [i] IPv4 address: 192.168.2.152/24 [i] Unable to find IPv6 ULA/GUA address [i] IPv6 address: [i] Using upstream DNS: Custom (74.40.74.40, 74.40.74.41) [i] Using upstream DNS: Custom (74.40.74.40, 74.40.74.41) [i] Not installing StevenBlack's Unified Hosts List [i] Not installing StevenBlack's Unified Hosts List [i] Query Logging off. [i] Query Logging off. [i] Using privacy level: 3 [✗] Check for existing repository in /etc/.pihole [i] Clone https://github.com/pi-hole/pi-hole.git into /etc/.pihole...^[[<0;53;27mHEAD is now at f47b8ed v6.4.3 (#6618) [✓] Clone https://github.com/pi-hole/pi-hole.git into /etc/.pihole [✗] Check for existing repository in /var/www/html/admin [i] Clone https://github.com/pi-hole/web.git into /var/www/html/admin...HEAD is now at b2a4078 Web v6.6 (#3808) [✓] Clone https://github.com/pi-hole/web.git into /var/www/html/admin [✗] Checking for group 'pihole' [✓] Creating group 'pihole' [✓] Creating user 'pihole' [i] FTL Checks... [✓] Detected x86_64 architecture [✓] Downloading and Installing FTL [✓] Installing scripts from /etc/.pihole [i] Installing configs from /etc/.pihole... [✓] Installing latest Cron script [✓] Installing latest logrotate script [✓] man pages installed and database updated [i] Testing if systemd-resolved is enabled [✓] Disabling systemd-resolved DNSStubListener [i] Restarting services... [✓] Enabling pihole-FTL service to start on reboot... [✓] Restarting pihole-FTL service... [\e[1;31m✗\e[0m] Failed to set dns.queryLogging. Try with sudo power root@xcsvr:/etc/systemd# 0;53;27m
[\e[1;31m✗\e[0m] Failed to set dns.queryLogging. Try with sudo power root@xcsvr:/etc/systemd# 0;53;27m 0: command not found 53: command not found 27m: command not found
Force Pi-hole v6 to immediately use port 8080 via the official Command Line Interface (CLI) tool:
Run this terminal command on your 192.168.1.152 server:
sudo pihole-FTL --config webserver.port "8080o,443os,[::]:8080o,[::]:443os"
Use code with caution.
Restart the core engine to force-bind the new ports:
sudo systemctl restart pihole-FTL
Check status and Open the Uncomplicated firewall port 8080 if necessary
sudo ufw status sudo ufw open 8080/tcp
Here is exactly how to configure Pi-hole and Apache to make this work.
Step 1: Add Local DNS Records in Pi-hole.
You must tell Pi-hole to intercept the public domains and resolve them to your internal server IPs instead of the public WAN IP.
Log into your Pi-hole admin dashboard (http://192.168.1.152:8080/admin).
Navigate to Local DNS > DNS Records on the sidebar.
Add the following three records:
Domain IP Address Description
sunsky.cloud 192.168.1.152 Points Nextcloud to the Apache server onlyoffice.sunsky.cloud 192.168.1.152 Points 1st OnlyOffice to the Apache server officepkg.com 192.168.1.152 Crucial: Points to Apache first, not .156
Note on officepkg.com: Because Apache handles your Let's Encrypt SSL certificates on 192.168.1.152, local traffic must hit Apache first so it can terminate the SSL connection before proxying the traffic to the second server (192.168.1.156).