How to Install Pi-hole on Ubuntu 24.04

How to Install Pi-hole on Ubuntu 24.04

How to Install Pi-hole on Ubuntu 24.04 (Network-Wide Ad Blocking Without a Pi)

Most Pi-hole guides assume you are running a Raspberry Pi. That is where the name comes from, and it is a perfectly good deployment target. But plenty of people have an Ubuntu server already running in their homelab, or a spare mini PC, or a VPS they want to use. You do not need a Raspberry Pi to run Pi-hole, and honestly, an Ubuntu 24.04 LTS server gives you a more powerful and flexible platform for it.

From the homelab: If you want to understand DNS properly, run Pi-hole on bare metal. You will learn about upstream resolvers, local DNS records, conditional forwarding, and DHCP – all the fundamentals that get abstracted away in cloud environments.

This guide covers the native installation method using Pi-hole’s official installer on Ubuntu 24.04, and the same steps apply to Ubuntu 26.04 LTS. It is written for Pi-hole v6 (released February 2025), which is what the installer gives you today. Not Docker, not a snap, not some third-party package. The curl-pipe-bash installer that the Pi-hole project maintains. If you would rather run it in Docker, I have a separate guide for that: Pi-hole in Docker. Both approaches work. The native install is simpler if Pi-hole is the only thing running on the machine. Docker is better if you are running multiple services and want clean isolation.

Why Ubuntu specifically? Because it is the most common Linux server distribution by a wide margin. Ubuntu 24.04 LTS has standard support until 2029 (26.04 LTS, released April 2026, until 2031), it is what most hosting providers offer as a default image, and if you are learning Linux for your career, Ubuntu is where you will spend most of your time. The principles here apply to Debian too, but the systemd-resolved issue we need to fix first is specifically an Ubuntu thing.

The short answer. On Ubuntu Server, free port 53 from systemd-resolved first (DNSStubListener=no, relink /etc/resolv.conf, restart the service; the installer also tries to do this itself, but that was not tested here). Then download the installer, read it and run it with sudo bash, choose your upstream DNS in the wizard, set the admin password with sudo pihole setpassword, and check dig @localhost ads.google.com answers 0.0.0.0. In Pi-hole v6, run pihole -g and pihole -up with sudo.

Tested on: Ubuntu Server 24.04.5 LTS (cloud image), Pi-hole installer from install.pi-hole.net on 15 November 2026: Core v6.6, Web v6.6.1, FTL v6.9. Where this guide quotes a command, its output or a screen, it came from that run.

Pi-hole on Ubuntu 24.04 in order: free port 53, run the installer, set the admin password, check it works, point your network at it
The install order that avoids the port 53 clash, then the three ways to send your network's DNS to Pi-hole.

Prerequisites

You will need:

  • Ubuntu 24.04 or 26.04 LTS server with a static IP address (or DHCP reservation on your router)
  • SSH access to the server (or direct console access)
  • sudo privileges on the account you are using
  • Access to your router’s admin panel for DNS configuration changes later

Static IP is non-negotiable. Pi-hole will become the DNS server for your entire network. If its IP address changes because DHCP gave it a different lease, every device on your network will lose internet access. Set a static IP on the server itself or create a DHCP reservation on your router before you start. Do this now, not later. Pi-hole’s own prerequisites page says the same: a static address, with a DHCP reservation being just fine. If subnet masks, gateways and the difference between a static address and a reservation are still hazy, our IP addressing fundamentals guide covers them with worked examples.

Fix the systemd-resolved Port 53 Conflict

This is the step that catches everyone. Ubuntu 24.04 runs a local DNS stub resolver called systemd-resolved by default. It listens on port 53, which is the standard DNS port. Pi-hole also needs port 53. Two services cannot bind to the same port. Pi-hole’s installer script has a step that disables the stub listener itself (it writes a drop-in file, 90-pi-hole-disable-stub-listener.conf, as read from install.pi-hole.net on 15 November 2026), so on a stock install it may cope without you. This guide frees the port first anyway, so you can see it is free before the installer runs and the same steps carry over to the Docker route. Running the installer without this step first was not tested in the lab.

I have seen people waste hours debugging this. It is documented in the Pi-hole FAQ, it is mentioned in every Pi-hole subreddit thread about Ubuntu, and people still miss it. Do not be one of them.

Step 1: Confirm the conflict exists

sudo ss -lntp | grep ':53 '

If you see systemd-resolve in the output, port 53 is occupied and you need to free it. A stock 24.04 install shows two listeners, 127.0.0.53 and 127.0.0.54; the one setting below frees both.

Before installing, ss shows systemd-resolved's stub listener holding port 53 on 127.0.0.53 and 127.0.0.54 on Ubuntu Server 24.04
Before installing: ss shows systemd-resolved's stub listener already holding port 53 on Ubuntu Server 24.04.

Step 2: Disable the DNS stub listener

sudo nano /etc/systemd/resolved.conf

Find the [Resolve] section and set these values:

[Resolve]
DNSStubListener=no
DNS=1.1.1.1
FallbackDNS=8.8.8.8

Step 3: Fix the resolv.conf symlink

This is the step people forget. Even after disabling the stub listener, Ubuntu still points /etc/resolv.conf at the old stub address (127.0.0.53). You need to update the symlink:

sudo rm /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

Step 4: Restart the service and verify

sudo systemctl restart systemd-resolved
sudo ss -lntp | grep ':53 '

The second command should return nothing. Port 53 is now free for Pi-hole. The DNSStubListener setting is described in the resolved.conf manual page.

The fix: DNSStubListener=no in resolved.conf, resolv.conf pointed at the real resolver file, systemd-resolved restarted and port 53 reported free
The fix: DNSStubListener=no in resolved.conf, resolv.conf pointed at the real resolver file, systemd-resolved restarted, and port 53 free.

Why not just disable systemd-resolved entirely? You could run sudo systemctl disable systemd-resolved, and some guides suggest exactly that. The problem is that your server then has no DNS resolution at all until Pi-hole is running. If Pi-hole fails to start, you cannot even apt install anything to fix it because apt needs DNS. The approach above disables only the stub listener while keeping the service running as a fallback. It is the safer path.

Install Pi-hole

With port 53 clear, the installation itself is straightforward. Pi-hole provides a single-command installer:

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

Yes, piping curl to bash makes security people uncomfortable. If you want to review the script first:

curl -sSL https://install.pi-hole.net -o pihole-install.sh
less pihole-install.sh
sudo bash pihole-install.sh
The Pi-hole installer saved to a file and its first lines read before it is run
The installer saved to a file and its first lines read before running it, the safer alternative to piping curl to bash.

The installer is a text-mode wizard built on the dialog tool: the arrow keys move between buttons and Enter accepts. It opens with a welcome screen and a donation notice, then asks the questions below, in this order (checked against the installer script from install.pi-hole.net and a lab run on a server with one network interface). The Pi-hole installation page lists the same one-line and download-first methods.

The Pi-hole Automated Installer welcome dialog: this installer will transform your device into a network-wide ad blocker
The installer's first screen, the Pi-hole Automated Installer welcome dialog.
  • Static IP Needed: a notice rather than a question, but its default button is Exit. Press the left arrow to highlight Continue before you press Enter, or the installer quits at this screen.
The Static IP Needed dialog with the Exit button highlighted by default and Continue beside it
The Static IP Needed notice. Exit is the highlighted default; move to Continue before pressing Enter.
  • Interface: only asked if the server has more than one network interface; pick the one on your LAN. With one interface the wizard skips it, as it did in the lab.
  • Upstream DNS provider: a menu of Google, OpenDNS, Level3, Comodo, three Quad9 variants, Cloudflare and Custom. Cloudflare (1.1.1.1) or Google (8.8.8.8) are fine starting points, and you can change this later. If you care about DNS privacy, read each provider’s resolver privacy policy before you choose: Cloudflare’s commits to never selling query data and is independently audited.
The upstream DNS provider menu listing Google, OpenDNS, Level3, Comodo, three Quad9 options, Cloudflare and Custom
The upstream DNS provider menu: Google, OpenDNS, Level3, Comodo, Quad9 (three variants), Cloudflare and Custom.
  • Blocklists: accept the default, StevenBlack’s Unified Hosts List (answer Yes). You will add more later.
The Blocklists dialog offering StevenBlack's Unified Hosts List, with Yes highlighted
The Blocklists screen offers StevenBlack's Unified Hosts List; Yes is the default.
  • Query logging: Yes. The logs are what make Pi-hole educational, not just functional.
The Enable Logging dialog asking whether to enable query logging, with Yes highlighted
The Enable Logging screen: would you like to enable query logging? Yes is the default.
  • Privacy mode: level 0, Show everything, at least initially. The other levels are Hide domains, Hide domains and clients, and Anonymous mode; you can lock this down later once you understand what your network is doing.
The privacy mode list with Show everything selected, then Hide domains, Hide domains and clients, and Anonymous mode
The privacy mode list: 0 Show everything (selected), 1 Hide domains, 2 Hide domains and clients, 3 Anonymous mode.

There is no web server question any more. Pi-hole v6 dropped lighttpd and PHP: the web interface and API are served by Pi-hole’s own DNS engine (pihole-FTL). By default it listens on ports 80 and 443 (with a self-signed certificate), and if another web server already holds those ports it falls back to 8080 and 8443. You can set the ports yourself in Settings > All settings (webserver.port) or with sudo pihole-FTL --config webserver.port '8080,8443s' followed by sudo systemctl restart pihole-FTL. The installer’s final screen tells you the address it ended up on.

At the end of the installation, a final “Installation Complete!” screen displays the addresses and a random admin password (the one below is from a throwaway lab machine). Write it down or change it immediately:

The Installation Complete dialog showing the server address (masked), the web interface address and a random admin password
The Installation Complete screen: the DNS server address and web interface address (masked here as <lab-ip>) and the random admin password of this throwaway lab machine.
sudo pihole setpassword
sudo pihole setpassword asks for the new password twice without echoing it and reports New password set
sudo pihole setpassword asks twice (nothing is echoed) and confirms the new password is set.

This prompts you to set a new web interface password. (On Pi-hole v5 this was pihole -a -p, which no longer exists.)

Configure Upstream DNS

Pi-hole is not a recursive DNS resolver by default. It forwards queries to an upstream provider. The installer asked you to pick one, but you can change or add more via the web interface at Settings > DNS. For the full lookup order a query follows, from the browser’s cache through the OS stub resolver to Pi-hole, its upstream resolver and the root, TLD and authoritative servers behind it, see what happens when you type a URL into a browser.

My recommendations:

  • Primary: Cloudflare (1.1.1.1) – fast, privacy-focused, WARP-compatible
  • Secondary: Quad9 (9.9.9.9) – blocks known malicious domains at the resolver level, good second layer

Avoid using your ISP’s DNS servers. They are typically slower, they log everything, and some ISPs inject ads or redirect failed lookups to search pages. The entire point of running Pi-hole is to control your DNS. Sending queries to your ISP undermines that.

Want full control? You can pair Pi-hole with Unbound, a recursive DNS resolver that queries root nameservers directly instead of forwarding to any third party. This eliminates the upstream provider entirely. It is a more advanced setup and adds some latency to initial lookups, but it means your DNS queries go nowhere except the authoritative nameservers for each domain. The Pi-hole project documents the setup in its official Unbound guide.

Point Your Network at Pi-hole

Pi-hole is running, but right now only the server itself is using it. You need every device on your network to send DNS queries to Pi-hole. There are three ways to do this, in order of preference.

Option 1: Change DNS in your router’s DHCP settings (best)

Log into your router’s admin panel and find the DHCP settings. Set the DNS server that gets handed to devices via DHCP to your Pi-hole server’s IP address. This way, every device that connects to your network automatically uses Pi-hole without any per-device configuration.

The advantage of DHCP-level DNS assignment is that Pi-hole sees each device’s individual queries. If you change the router’s own DNS settings instead (Option 2), all queries appear to come from the router’s IP, and you lose per-device visibility in the logs.

Option 2: Change the router’s DNS servers

If your router does not expose DHCP DNS settings separately (many consumer routers hide this), change the router’s own DNS servers to your Pi-hole IP. This works but means Pi-hole sees all queries coming from the router rather than from individual devices.

Option 3: Per-device manual configuration

If you have a locked-down ISP router that will not let you change DNS settings at all (looking at you, BT Home Hub and Sky Q), you can manually set DNS on each device. This is tedious but it works.

The secondary DNS trap. If you set a public DNS server (like 1.1.1.1) as your secondary DNS alongside Pi-hole as primary, some devices will use the secondary instead, bypassing Pi-hole entirely. Android is particularly guilty of this. If you want consistent filtering, set both primary and secondary DNS to your Pi-hole IP. The trade-off is that if Pi-hole goes down, DNS stops working. In practice, Pi-hole on Ubuntu LTS is very stable, but it is a decision you should make deliberately.

After changing your DNS settings, renew DHCP leases on your devices. The quickest way is to disconnect and reconnect to Wi-Fi, or restart the device. Within a few minutes, queries should start appearing in the Pi-hole dashboard.

The Gravity Database and Blocklist Management

Pi-hole’s blocklist database is called Gravity. When you add a blocklist URL, Pi-hole downloads the list and imports the domains into the Gravity database. This is a local SQLite database, not a text file, which is why Pi-hole can handle millions of blocked domains without performance degradation.

To add blocklists, go to Lists (under Group Management) in the web interface. A fresh install has one list, the Steven Black hosts file, which was 77,310 domains on the day of the lab run; the page is titled “Subscribed lists group management”.

Pi-hole's Subscribed lists page showing the default StevenBlack list, enabled
The Lists page (titled Subscribed lists group management) with the one default list, enabled.

Here are the lists I run:

  • Steven Black Unified Hosts: https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts – the default, well-maintained, covers the basics
  • OISD Full: https://big.oisd.nl/ – aggressive but well-curated, catches a lot of telemetry
  • Hagezi Pro: https://cdn.jsdelivr.net/gh/hagezi/dns-blocklists@latest/adblock/pro.txt – excellent balance of coverage and false positive avoidance

After adding lists, update Gravity to pull them in. Pi-hole v6 refuses this command without root, so use sudo:

sudo pihole -g
pihole -g refused without root and telling you to use sudo, then sudo pihole -g rebuilding the gravity database with 77,310 domains
pihole -g is refused without root (it tells you to use sudo); sudo pihole -g then rebuilds the gravity database, 77,310 domains on the day.

Or use the web interface: Tools > Update Gravity. Gravity updates automatically on a weekly cron schedule, but always run it manually after adding new lists.

More blocklists does not mean better blocking. Aggressive lists break things. Banking sites, CAPTCHAs, app login flows, and streaming services can all stop working if you over-block. Start with the defaults plus one additional list. Live with it for a week. If nothing breaks, add another. If your partner’s banking app stops working at 9pm on a Sunday, you will regret going straight to the nuclear option.

Group Management for Family Members

Pi-hole supports group management (since v5, and still in v6), which is genuinely useful if you share a network with other people. The concept is simple: you can assign devices to groups, and each group can have different blocklists and allow rules.

Why this matters: your filtering needs are probably different from your children’s. You might want aggressive blocking on the kids’ devices but more relaxed rules on your own machine where you need access to ad-supported tools for work.

Pi-hole's group management page showing the Default group
Group management, Groups page, with the built-in Default group.

To set this up:

  1. Go to Group Management > Groups and create groups (e.g., “Adults”, “Kids”, “IoT Devices”)
  2. Go to Group Management > Clients and assign devices to groups by their IP or MAC address
  3. Go to Group Management > Lists and assign blocklists to specific groups
  4. Go to Group Management > Domains and assign allowlist entries to specific groups

A practical example: I have an “IoT” group with the most aggressive blocklists applied. Smart TVs, smart speakers, and home automation devices do not need access to advertising or analytics networks. They get blocked hard. My personal machines are in a group with more permissive rules because I occasionally need to access sites that aggressive lists would break.

Allowlisting False Positives

Things will break. It is not a question of if. Someone in your household will try to do something and it will not work, and the cause will be Pi-hole blocking a domain that the service depends on.

The diagnostic process:

  1. Open the Pi-hole query log (Query Log in the web interface)
  2. Filter by the device having problems
  3. Look for blocked entries (shown in red) that correspond to the service that is broken
  4. Click the blocked domain and add it to the allowlist (v6 renamed the whitelist and blacklist to allowlist and denylist; from the command line it is sudo pihole allow example.com)

The same list is managed on the Domains page, where the green button adds to the allowed domains and the red one to the denied domains:

Pi-hole's Domain management page with the buttons to add to denied domains or allowed domains
The Domain management page: red button to add to denied domains, green button to add to allowed domains.

Common domains you may need to allowlist:

  • s.youtube.com – YouTube history and watch later
  • clients4.google.com – Android connectivity checks
  • captive.apple.com – Apple Wi-Fi portal detection
  • outlook.office365.com – Microsoft 365 email
  • Your bank’s CDN and authentication domains (these vary)

The community maintains a list of common false positives at https://github.com/anudeepND/whitelist. Review it, but do not blindly import the whole thing. Some entries will re-enable tracking you specifically wanted blocked.

Keeping Pi-hole Updated

Native Pi-hole installations update through the built-in updater:

sudo pihole -up
sudo pihole -up reporting that Core, Web Interface and FTL are up to date
sudo pihole -up reports whether Core, the Web Interface and FTL are current (all up to date on the day).

This updates Pi-hole core, the web interface, and FTL (the DNS engine). Pi-hole v6 needs sudo for it, like gravity. The project’s update page gives the same one-line command. Run it periodically. Pi-hole does not auto-update, and running old versions means missing security patches and new features.

For the underlying Ubuntu system:

sudo apt update && sudo apt upgrade -y

If a kernel update requires a reboot, Pi-hole will come back automatically since it installs as a systemd service. Your network will lose DNS for the thirty seconds or so that the server is rebooting, which most devices handle gracefully by retrying.

Check the release notes before major version upgrades. Pi-hole version transitions (like v5 to v6) can involve database migrations and configuration changes. The Pi-hole team is good about documenting these, but running pihole -up blindly on a major version bump is asking for trouble. Spend two minutes reading the release notes. It could save you two hours of troubleshooting.

Verifying Pi-hole Is Working

After setup, run these checks:

# Test DNS resolution through Pi-hole
dig @localhost google.com

# Test that blocking is working
dig @localhost ads.google.com
# Should return 0.0.0.0 or NXDOMAIN

# Check Pi-hole status (sudo avoids a permission warning, see below)
sudo pihole status

# The old "pihole -c" stats screen is gone in v6; for a terminal
# dashboard, install PADD: https://github.com/pi-hole/PADD
dig resolves google.com, returns 0.0.0.0 for ads.google.com, pihole status without sudo prints a permission warning, and pihole -v lists Core v6.6, Web v6.6.1 and FTL v6.9
dig resolves google.com and answers 0.0.0.0 for ads.google.com. pihole status run without sudo prints the permission warning; pihole -v lists Core v6.6, Web v6.6.1 and FTL v6.9.

Run pihole status without sudo on v6 and it prints a permission warning twice, /etc/pihole/pihole.toml exists but cannot be read (Permission denied), around the same status lines, as the screenshot above shows; with sudo the warning is gone. To use the command line as yourself, Pi-hole’s post-install page says to add your user to the pihole group: sudo usermod -aG pihole $USER, then log in again. In the lab, pihole status then ran without the warning, while pihole -g still said it needs root, so keep sudo for gravity and updates.

Then open the web interface at http://YOUR-SERVER-IP/admin (or port 8080 if the installer had to fall back) and watch the query log for a few minutes. You should see queries from your devices appearing and a percentage of them being blocked.

The Pi-hole v6 dashboard after a few test lookups, with some queries blocked
The Pi-hole dashboard after a few test lookups, some to known ad domains.

If the dashboard shows zero queries, your devices are not using Pi-hole as their DNS server. Go back to the router configuration section and double-check your settings.

Watch out: After installation, make sure you change your router’s DHCP settings to hand out the Pi-hole’s IP as the DNS server. Without this step, only devices you have manually configured will use Pi-hole.

Where you’ll meet this at work

In a company the same job is called DNS-layer security or web content filtering. Cisco’s Umbrella documentation lists DNS-layer security as one of its features alongside the firewall and secure web gateway, and web content filtering in Microsoft Defender for Endpoint blocks website categories on managed devices, whether users are on your network or away.

What maps one to one: a blocklist is a threat or category policy, groups are policies per device group, the query log is where you start when a user says a site is broken, and the allowlist is the exception process. What doesn’t: Pi-hole only filters devices that use it as their resolver, so a laptop on hotel Wi-Fi is outside its reach, and it has no central management across sites and no policies tied to a user rather than a device, which the commercial products add. The home version teaches the habit that carries over: when something breaks, read what the filter blocked before you change anything.

Key Takeaways

  • Check port 53 first. On stock Ubuntu, systemd-resolved holds it. The installer is written to release it, but disabling the stub listener and updating the resolv.conf symlink yourself takes a minute, lets you confirm the port is free, and is required for the Docker route.
  • Start with minimal blocklists. The defaults plus one additional list is enough. Add more after a week of living with it. Over-blocking creates more problems than it solves.
  • Use group management. Different devices and users have different needs. IoT devices get aggressive blocking. Personal machines get more permissive rules.
  • Set both DNS entries to Pi-hole. A public secondary DNS lets devices bypass your filtering. Decide whether total coverage or fallback resilience matters more to you.
  • Keep a paper note of recovery steps. When DNS is down, you cannot search for how to fix DNS. Write your server’s IP and the basic commands somewhere physical.

Related Guides

Related Guides

If you found this useful, these guides continue the journey:

The RTM Essential Stack - Gear I Actually Use

Enjoyed this guide?

New articles on Linux, homelab, cloud, and automation every 2 days. No spam, unsubscribe anytime.

Scroll to Top