How to Install Pi-hole on Linux Ubuntu v 24.04 server and Ubuntu v 26.04 server
If you have two Ubuntu servers on the same LAN network, and one server has Nextcloud installed and the other server has ONLYOFFICE Document Server installed, and if you are having trouble connecting ADDON for ONLYOFFICE Document Server (within the admin panel of Nextcloud) to and with the OnlyOffice Document Server that is installed on the other Ubuntu server, then try this before you buy a new router that would eliminate the Hairpin NAT (NAT Loopback) restriction that is built into most routers. The NAT Loopback restriction is often the reason Nextcloud and OnlyOffice cannot connect with each other when installed on the same server box or between two server boxes residing on the same LAN network.
To install Pi-hole on your standalone Ubuntu 24.04 and Ubuntu 26.04 bare-metal servers, you must first disable Ubuntu's built-in DNS stub listener (systemd-resolved). If you do not disable it, Pi-hole will fail to install because port 53 (DNS) will already be occupied.
Run the following sequential steps on both machines to complete the installation.
1. Disable the Conflicting System DNS DaemonRun these commands on both Ubuntu servers to free up port 53:
# Stop and disable the systemd-resolved service sudo systemctl stop systemd-resolved sudo systemctl disable systemd-resolved # Remove the symbolic link to the resolved configuration file sudo rm /etc/resolv.conf # Create a fresh, static DNS configuration file pointing to upstream DNS echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf
2. Run the Official Pi-hole Automated InstallerExecute the network installer script directly from the Pi-hole Official Site via the command line:
bash
curl -sSL https://pi-hole.net | bash
3. Navigate the Interactive Setup WizardAn automated, blue-screen wizard will launch in your terminal. Step through the settings using your arrow keys and the Tab key:
Static IP Warning: Select Acknowledge. The script will confirm your current LAN IPs (192.168.1.150 on the 24.04 node and 192.168.1.156 on the 26.04 node).
Upstream DNS Provider: Choose any provider you prefer, such as Cloudflare (1.1.1.1) or Google (8.8.8.8).
Blocklists: Press Enter to accept the default StevenBlack blocklist setup.
Web Admin Interface: Choose Yes to install the web dashboard layout.
Web Server (lighttpd): Choose Yes to install the web server dependencies.
4. Note the Admin Password and Access the Dashboard
Once the installation script terminates, it will print a confirmation block to your terminal containing your unique, randomized admin panel password.
Open your web browser and navigate to the respective management panels:
Nextcloud Box Dashboard: http://192.168.1
ONLYOFFICE Box Dashboard: http://192.168.1
Note: If you ever lose or want to change this password later, log into the server's terminal and run:
pihole -a -p
5. Final Step: Configure Ubuntu to Use Its Own Pi-hole
Now that Pi-hole is running locally on both servers, you must force the operating systems to resolve DNS requests using their local loops.
Open the network config file on each machine:
sudo nano /etc/resolv.conf
Change the nameserver IP to look inward at itself:
nameserver 127.0.0.1
Save and close the file. Your cURL requests will now seamlessly hit the local Pi-hole instance, discover your custom LAN records, and establish an encrypted SSL session without ever touching your router.
= = = = = = = =
How to add custom domain records:
To route your Nextcloud and ONLYOFFICE traffic entirely inside your local network, you must add two custom Local DNS Records into the Pi-hole instance that your Nextcloud server is using.
Follow these exact steps to create the records and verify that they are working:
1. Log Into Your Pi-hole Admin PanelOpen your web browser.
Navigate to your Pi-hole dashboard (e.g., http://192.168.1 or http://192.168.1).
Click Login in the sidebar.
Enter the administrator password generated during your installation.
2. Navigate to the Local DNS Settings
Look at the left-hand navigation sidebar.
Click on Local DNS.
Click on the sub-menu item labeled DNS Records.
3. Add the ONLYOFFICE RecordThis step forces your Nextcloud server to find ONLYOFFICE on your LAN instead of going out to the internet.
In the Domain box, type exactly:
YourOnlyOfficeDomain.com
In the IP Address box, type the local IP of your ONLYOFFICE server: 192.168.1.156
Click the green Add button.
4. Add the Nextcloud Record
This ensures that when ONLYOFFICE responds or loops back, it routes straight to the Apache proxy on the Nextcloud box.
In the Domain box, type exactly:
YourNextcloudDomain.com
In the IP Address box, type the local IP of your Nextcloud server: 192.168.1.150
Click the green Add button.
You will now see both domains listed at the bottom of the page in the “List of local DNS records” table.
5. Verify the Routing is Active
Log back into your Nextcloud Server (192.168.1.150) terminal via SSH to test that the local DNS is intercepting the requests.
Run this command:
bash
nslookup officepkg.com
Success Looks Like: The output should state that the server answering is 127.0.0.1 (or your local Pi-hole IP), and the returned Address must be 192.168.1.156.
If it returns a public IP: Your server is not using Pi-hole for its DNS yet.
Re-run
sudo nano /etc/resolv.conf
and ensure it says nameserver 127.0.0.1.
Once nslookup confirms the local IP address, run your original curl command:
curl -Iv https://officDomain.com
It will connect instantly over SSL, and you can successfully click “Save” in your Nextcloud ONLYOFFICE admin panel settings.
