how to install pi-hole on ubuntu

How to Install Pi-Hole on Ubuntu (Beginner’s Guide)

Ads are all over the place on the Internet. Most people develop a sixth sense to ignore them, use a browser extension like AdBlock to hide some of them, or block everything on their whole network by installing Pi-Hole on Ubuntu. How do you do this? I will explain my setup in this article.

Pi-Hole is a free and open-source ad blocker that can be installed on any Linux distribution with only one command line: “curl -sSL https://install.pi-hole.net | bash”. Once done, the network configuration needs to be updated to use it as the main DNS server.

This might seem simple at first glance, but I bet you’ll need more details on how to do this safely and efficiently. Keep reading to see how to set up Pi-Hole step-by-step on your network.

If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?

Pi-Hole server Installation on Ubuntu

Pi-Hole requirements

Pi-Hole is a lightweight solution, and that doesn’t require much processing power to install it. In fact, it’s mainly used on the Raspberry Pi, a tiny computer with limited CPU and RAM, so it shouldn’t be an issue on any standard computer.

In their documentation, Pi-Hole recommends at least 2 GB of free space on the disk and 512 MB RAM.

Your computer will be perfect, but you can also use a Raspberry Pi 4 or a minimal Intel NUC for example. I read that you can even install it on a Synology NAS, with a docker container (I have this one on Amazon, but you can find cheaper models).

Warning: Pi-Hole may not be supported on the latest Ubuntu release, check this link to verify.

You can install Pi-Hole directly on your computer if you are using Ubuntu, but it’s probably better to install it on something you’ll run 24/7. For example, if you configure the whole network to use Pi-Hole, Internet won’t work on other devices if your computer is off or in sleeping mode. This would not be a great experience.

That’s why I suggest using a Raspberry Pi (you can install Ubuntu on it), a NAS or any device that you can leave running all the time.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Note: If you are trying this on a Raspberry Pi with the default operating system, I have a detailed tutorial on how to install Pi-Hole on Raspberry Pi. In this article, I’ll focus on Ubuntu.

Update your operating system

Once your hardware is selected and Ubuntu is installed, the first thing to do is to update your system. It’s a good practice to follow before installing anything on your system, just to avoid dependency issues and version incompatibility.

You can do this easily in a terminal:
sudo apt update
sudo apt upgrade

Or use the software updater tool in the graphic interface if you are using the Desktop version:

Join Our Community!

Connect, learn, and grow with other Raspberry Pi enthusiasts. Support RaspberryTips and enjoy an ad-free reading experience. Get exclusive monthly video tutorials and many other benefits.

Learn more

Click on “Install now” and type the user password to confirm the installation.
A reboot is probably a good idea if you have many updates to catch up on.

Then you’ll also need to install curl on your system if not already there:
sudo apt install curl

The Pi-Hole script will install anything else after that.

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

Pi-Hole installation script

Once your system is ready, the installation can be done with only one command, by copying and pasting this into a terminal:
curl -sSL https://install.pi-hole.net | bash

The process is almost automatic, but you still need to answer a few questions to adjust your settings:

  • Type your user password, and the installation starts:
  • A few seconds later, a wizard will show up with a few questions for you to answer:

    Just confirm by pressing Enter for the first few questions.
  • Then choose your DNS provider:

    Google is fine, but you can choose another one if you prefer.
  • Pi-hole relies on third-party lists to block ads. By default, it will use StevenBlack’s host list, but you can deselect it if you want (not recommended).
    Press Enter to continue (and the space bar to select/deselect).
  • Then, select the protocols you want to use (I recommend keeping both).
  • Pi-Hole will use a static IP address (to avoid reconfiguring everything each time it uses a new IP).
    The next step is to configure if you want to keep the current IP or set another one manually.
    It depends on your network, at home you can probably keep the default one without any major issues.
  • Then confirm to enable the web interface and the web server (highly recommended):
  • A couple of questions later, the installation wizard will configure everything as requested.

Make sure to not use the default password and move to the next step.

Configure your clients to use Pi-Hole

Once your server is installed, the next step is to configure your network to use this server. Pi-Hole works like a DNS server, so you need to change the primary DNS server on all of the devices to use the Pi-Hole IP address.

This can be done manually on each device, but the easiest way is to change the default DNS server in your DHCP configuration.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Edit the DHCP configuration to set Pi-Hole as the default DNS

The easiest way to config all devices at once is to go to your DHCP server configuration and set the primary DNS server to the Pi-Hole server IP address.

If you are installing this at home, your DHCP server is probably your Internet router.
I won’t explain how to do this in detail, as it will be different for each provider and router, but as a whole, the idea is to find the DHCP settings on the web interface and change the DNS server IP address.

By default, it’s probably the DNS server from your provider.
In my case, it was in the DNS settings:

Once you find something like this, remove the default values and set the primary DNS server to your Pi-Hole installation IP address (probably something like 192.168.1.X or 192.168.0.X). Leave the secondary DNS server empty.

It may take a few hours to update the configuration on all devices on your network, but it will be done automatically.

Change the network configuration on each client to use Pi-Hole

The alternative is to manually update the configuration on each device you want to use with Pi-Hole. This might take more time, especially if you have many devices on your network, but this way you can make sure everything is working before breaking the Internet for the whole family!

On Windows 10:

  • Right-click on the “Start Menu” and choose “Network Connections”.
  • Then click on “Change adapter settings”.
  • Right-click on your current connection and choose “Properties”.
  • Double-click on “Internet Protocol Version 4 (TCP/IPv4)”.
  • Set the DNS server to static and enter your Pi-Hole server IP Address.
    Keep the secondary DNS server empty.

On Linux and Mac OS:

  • If you have a graphical interface, you’ll find the network settings in the System Preferences.
  • If not, you can edit the /etc/resolv.conf file and replace the current DNS server with the Pi-Hole IP address.
    I explain how to change the DNS server on a server edition of Linux in more details in this article. Click on the link to learn more, as the resolv.conf file might not work depending on your distribution.

On mobile, it’s in your Wi-Fi settings.
Click details or edit the network on a network to see the DNS configuration.

How to know if Pi-Hole is working?

To know if Pi-Hole is working, you can go to the web interface and check if it’s blocking ads. Another way is to try to access a domain hosting ad (like doubleclick.net) and verify that the Pi-Hole page appears instead of the website content.

The web interface is enabled on http://localhost/admin (if installed on your computer) or http://IP_Address/admin (if installed on another computer). The default password is provided at the end of the installation.

Pi-Hole installation guide on Raspberry Pi
Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Pi-Hole FAQ

Can Pi-Hole run on any Linux distribution?

Pi-Hole is officially supported on Raspberry Pi OS (Raspbian), Ubuntu, Debian, Fedora and CentOS. As most Linux distributions are based on them, they should run on almost any of them.

Just check the exact supported release on this page before trying to install it. They are often a little behind when a new version is available. For example, at the time of writing (July 2021, Ubuntu 21.04 is not yet supported).

Consider using docker if you experience any compatibility issues with your system.

What can Pi-Hole be installed on?

The prerequisites to install Pi-Hole are 2 GB of disk space and 512 MB of RAM, so it can run on almost any computer, even the older ones. Raspberry Pi and other single-board computers are also supported as long as a supported operating system is installed.

My recommendation is to use a Raspberry Pi (as it’s the cheapest option), plug it somewhere on your network and keep it on all the time.

Warning: current prices are all over the place for a new Raspberry Pi. Make sure to check this article to pay the right price when buying a Raspberry Pi. I also give a few tips to find one in stock (which currently isn’t that easy).

What can I do with Pi-Hole?

The main purpose of Pi-Hole is to block ads on the Internet, by blocking their servers at a network level. Pi-Hole can also be used as a DHCP server and a network monitor.

Does Pi-Hole stop YouTube ads?

As Pi-Hole is working at a network level, it’s not the best option to block YouTube ads. On YouTube, ads and videos are served from the same domain, so Pi-Hole will block both or none, it can’t analyze the exact content.

If blocking YouTube ads is your main goal, a browser extension like AdBlock has a better chance of success.

Does Pi-Hole stop malware and phishing?

Pi-Hole won’t natively stop malware and phishing on your devices, but you can add additional block lists with domains that are known to host malware or act as phishing. It won’t have a 100% success rate, but it might increase the overall security of your network.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

If you are looking for exclusive tutorials, I post a new course each month, available for premium members only. Join the community to get access to all of them right now!

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

Similar Posts